2011-04-17 39 views
0

請我有時間這個問題不解決創立和adressing您爲:)機械手尚未顯示

我有UIPickerView它必須從視圖的底部顯示,當用戶點擊在爲UITextField(這是我的應用程序的要求強迫我做的),所以我實現這個方法來捕捉文本字段的觸摸事件:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 

    UITouch *touch; 
    touch=[touches anyObject]; 
    CGPoint point=[touch locationInView:self.view]; 
    if(CGRectContainsPoint([typeCarburantTextField frame],point)) 
    { 
     [self pickerTypeCarburantsShow]; 

    } 

} 

這種方法來防止鍵盤被顯示在用戶的時候點擊文本字段:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 

    return NO; 

} 

pickerTypeCarburantsShow

-(IBAction)pickerTypeCarburantsShow{ 

     [UIView beginAnimations:nil context:nil]; 
     [UIView setAnimationDuration:0.5]; 
     CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240); 
     pickerViewTypesCarburants.transform=transform; 
     [self.view addSubview:pickerViewTypesCarburants]; 
     [UIView commitAnimations]; 

    } 

我所有的IB連接都還不錯,但是當我運行,我點擊的UITextField鍵盤不會出現,但我沒有看到選擇器顯示 pleaaaase幫助,thx預先:)

回答

1

什麼你可能想大概是這樣的..

的UITextField具有這個屬性,

inputView

自定義輸入視圖中顯示當文本字段成爲第一個響應者。

@property (readwrite, retain) UIView *inputView 

討論 如果在此屬性的值爲零,該文本字段顯示標準系統鍵盤當它成爲第一個響應者。爲該屬性分配自定義視圖會導致該視圖被呈現。

此屬性的默認值爲零。

所以,顯示另一視圖代替所要求的鍵盤,所有被用來設置視圖,在這種情況下,uipickerview或其作爲inputView爲文本字段容器...

例如,爲了表現出一定的pickerview代替鍵盤,你可能想

textView.inputView = [[UIPickerView alloc] initWithFrame:CGRectMake(...)]; 
+0

嗨,我的視圖的名稱,其中包含選擇器是「pickerViewTypesCarburants」。應該變成這樣:@property(readwrite,retain)UIView * pickerViewTypesCarburants ??併爲合成?另外,我不明白你的第二個陳述,應該是textView,不應該是pickerViewTypesCarburants視圖? – Malloc 2011-04-17 19:34:23

+0

我已編輯答案...讓我知道如果你需要它澄清 – govi 2011-04-17 19:40:01

+0

所以..如果我正確理解它,它將textView.inputView = [自我pickerViewTypesCarburants],考慮到uitextfield被稱爲文本視圖 – govi 2011-04-17 19:40:54

1

您的PickerView是否有它的Delegate和DataSource集?它不會出現在其他地方。

+0

是的,我有它,如果你需要其他方法代碼,請告訴我:)) – Malloc 2011-04-17 19:25:41

+0

@Malek請顯示你的'pickerTypeCarburantsShow'方法,(通過編輯添加到你的問題)。 – 2011-04-17 19:58:35

+0

好吧,我編輯它:)) – Malloc 2011-04-17 20:22:04

0

我的問題得到解決,所以這個問題是在的UITextField委託方法,我已經實現了錯誤的方法:

-(BOOL)textFieldShouldReturn:(UITextField *)textField{ 

    [textField resignFirstResponder]; 
    return YES; 
} 

相反,它應該是這個方法來顯示UIPickerView:

- (void)textFieldDidBeginEditing:(UITextField *)textField{ 
    [textField resignFirstResponder]; 
    [self pickerTypeCarburantShow]; 
} 

其中pickerTypeCarburantShow是被認爲動畫整個UIPickerView視圖的IBAction爲方法..希望這種幫助是誰在同樣的問題掙扎:)