iOS UITextField-取消自定义 inputView
我正在为某些文本字段使用自定义 inputView,但是当我在文本字段上调用 resignFirstResponder 时,自定义输入视图不会忽略...有什么建议吗?
UITextField *f=[[UITextfield alloc] init];
UIView *view=[[UIView alloc] initWithFrame..];
[f setInputView:view]; //random example of how to set a textfields input view to a custom view
经过一些研究,这个问题仅在使用模态视图中呈现的 viewController 时出现......否则它工作正常......
谢谢
-Daniel
I am using a custom inputView for some textfield, however when i call resignFirstResponder on the textfield, the custom input view does not dismiss...any suggestions?
UITextField *f=[[UITextfield alloc] init];
UIView *view=[[UIView alloc] initWithFrame..];
[f setInputView:view]; //random example of how to set a textfields input view to a custom view
After some research, this issue only occurs when working with a viewController thats presented in a modal view...it works ok otherwise...
Thanks
-Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在视图本身或其任何超级视图上调用
endEditing:
,而不是调用resignFirstResponder
。endEditing:
将在所有子视图中搜索任何具有第一响应者状态的视图,并要求其退出。endEditing:
采用布尔标志作为参数。如果设置,将强制第一响应者辞职;否则,您可以允许它保持焦点(例如,如果输入无效)。对于 UITextField,这是由委托的shouldEndEditing:
方法确定的。一般来说,一个好的使用模式是:
Instead of calling
resignFirstResponder
, you should callendEditing:
on the view itself or any of its superviews.endEditing:
will search all subviews for any view that has first responder status, and ask it to resign.endEditing:
takes a boolean flag as a parameter. If set, it will force the first responder to resign; otherwise, you can allow it to keep focus (if input is invalid, for example). For a UITextField, this is determined by the delegate'sshouldEndEditing:
method.In general, a good pattern to use is:
如果您使用模态视图,请确保启用自动键盘关闭。将此代码添加到您的视图控制器中:
If you use a modal view, make make sure to enable automatic keyboard dismissal. Add this code to your view controller: