iPad popover textfield - resignFirstResponder不会关闭键盘

问题描述:

我有两个文本字段的电子邮件和密码。当在常规视图上显示字段时,以下代码可以正常工作,但是当它们在弹出窗口上时,resignFirstResponder不起作用(becomeFirstResponder工作)。两个字段都调用了textFieldsShouldReturn。
如果我错过了什么,有什么想法吗?
谢谢!

I have two text fields email and password. The following code works fine when the fields are presented on a regular view but when they are on a popover, the resignFirstResponder does not work (becomeFirstResponder works). textFieldsShouldReturn was called for both fields. Any idea if I am missing something? Thanks!

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

     if (theTextField == email) {
         [password becomeFirstResponder];
         return NO;
     }

     [theTextField resignFirstResponder];
     return NO;
}


检查这个问题:

覆盖 disablesAutomaticKeyboardDismissal 返回,如下所示修复了我的同样问题。您应该将此代码放入视图控制器,从中启动键盘:

Overriding disablesAutomaticKeyboardDismissal to return NO as below fixed the same problem of mine. You should put this code to your view controller, from which you initiate the keyboard:

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}