简体   繁体   English

iPhone SDK:resignFirstResponder无法正常工作

[英]iPhone SDK: resignFirstResponder not working

For some reason, resignFirstResponder is not working. 由于某种原因,resignFirstResponder无法正常工作。 I am not sure why? 我不确定为什么吗? I have tried to call it from textFieldDidEndEditing and nothing happens. 我试图从textFieldDidEndEditing调用它,什么也没发生。 A NIB is being used and each's delegate is pointing to files owner. 正在使用NIB,每个代表都指向文件所有者。

What needs to be done to get the keyboard to dismiss? 要关闭键盘需要做什么?

Thanks. 谢谢。

actually you should return NO so that the text field does not begin editing at all. 实际上,您应该返回NO,以使文本字段完全不会开始编辑。 If it does, the firstresponder gets set and the keyboard pops up again. 如果是这样,则设置第一响应者,然后再次弹出键盘。

Don't use -textFieldDidEndEditing . 不要使用-textFieldDidEndEditing That's called after the text field resigns firstResponder status, which is what you're trying to use it as a hook to make happen. 在文本字段退出firstResponder状态后调用该方法,这就是您要使用它作为实现目标的原因。 Cart before horse, chicken-and-egg kind of problem. 马车前马,鸡和蛋有点问题。

Instead use -textFieldShouldReturn to get triggered when the return key is pressed (and remember to return YES; from that.) Also float a clear custom button behind the elements of the view and handle a "background tap" that goes through all the text fields on your view and resigns first responder on the lot of them. 而是在按下返回键时使用-textFieldShouldReturn来触发(并记住要从中return YES; 。)还要在视图元素后面浮动一个清晰的自定义按钮,并处理遍历所有文本字段的“背景敲击”根据您的看法,并请他们中的第一响应者辞职。

Make sure your setting your delegates for the textfield. 确保您为文本字段设置了代理。

myTextField.delegTe = self;

And you are using in your header: 并且您在标题中使用:

<UITextFieldDelegate>

EDIT: 编辑:

Try: 尝试:

if(textField == myTextField){
    [textField resignFirstResponder];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM