2011-02-13 78 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