2011-02-13 121 views
0

我已經在我的項目3的UITextField問題與當焦點離開一個UITextView解僱鍵盤

我需要的時候裏面其中一個(uitextfield2)的自定義水龍頭子視圖出現,並需要鍵盤當輕敲出現彼此(uitextfield1)

的問題是,當我在uitextfield1選項卡,鍵盤出現,而不是去連我點擊返回或點擊另一個uitextfield2

我需要的鍵盤消失,當我點擊出來的uitextfield1或點擊返回時

我用下面的代碼

- (BOOL)textFieldShouldReturn:(UITextField *)textField { // When the return button is pressed on a textField. 


    [textField resignFirstResponder]; // Remove the keyboard from the view. 
    return YES; // Set the BOOL to YES. 
} 

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{ 
    // [textField resignFirstResponder]; 
    [self SelectModalityClick]; // will be called If i tapped inside the uitextfield2 to display the custom view 

    return NO; 

} 

回答

0

當您創建UITextField實例,您可以設置inputView到任何UIView子類,你想是這樣的。

UITextField *aTextField = [[UITextField alloc] initWithFrame:aRect]; 
aTextField.inputView = myCustomInputView; // Set this up in your viewDidLoad method 
aTextField.delegate = self; 
aTextField.tag = MyCustomInputView; // #define this as some integer 
[self.view addSubview]; 
[aTextField release]; 

你不應該需要做什麼特別的做出正確輸入視圖顯示,如果你有第一個響應者爲UITextField實例變量,只是給它分配在textFieldShouldBeginEditing:和辭職textFieldShouldReturn其第一個響應狀態:。

+0

它在新屏幕中打開uiview,而不是在屏幕按鈕處顯示子視圖 – Ali 2011-02-14 11:29:44

相關問題