在 UINavigationbar 中添加完成按钮
当用户触摸特定文本字段或文本视图时,如何向 UINavigationbar 添加完成按钮?
或者更好的方法是检测键盘何时显示,然后显示按钮。
我希望使用“完成”按钮来关闭键盘,就像在标准 Notes 应用程序中一样。
How does one add a done button to a UINavigationbar when the user touches a specific textfield or textview?
Or would a better way be to detect when the keyboard is showing, and then display the button.
I would like the done button to dismiss the keyboard like in standard Notes application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该采用委托协议,因为我相信您在这方面具有优势。您可以这样做 -
但如果您观察通知,您将无法知道哪个是第一响应者。当然,如果您只需要担心一个对象,那么这并不是什么大问题。
You should adopt the delegate protocol as I believe you are at an advantage there. You can do this –
But if you were to observe the notification, you can't know which one is the first responder. Of course, it is not much of a problem if you have only one object to worry about.
您可以尝试与此类似的操作:
并且还
可以根据需要自定义以下内容
,然后删除
- (void)textFieldDidEndEditing:(UITextField *)textField
和- (void) 中的按钮textViewDidEndEditing:(UITextView *)textView
只要记住设置委托即可!
You could try something similar to this:
and also
with the following customized as you like
then remove the button in
- (void)textFieldDidEndEditing:(UITextField *)textField
and also in- (void)textViewDidEndEditing:(UITextView *)textView
Just remember to set up the delegates!