处理“完成” textViewDidEndEditing 外部键盘上的按钮
当按下“完成”时,我知道 textViewDidEndEditing:
被调用。有时它也被其他操作调用。
我想要一个仅在按下“完成”时才调用的方法 - 独占。我一直在阅读代码片段,但没有看到有人这样做。顺便说一下,我没有使用任何 XIB 来表达我的观点。
这可能吗?
When "Done" is pressed I know textViewDidEndEditing:
is called. It is also sometimes called by other actions.
I want a method that is only called when "Done" is pressed -- exclusively. I've been reading around for snippets of code, but don't see anybody doing this. I am not using any XIB for my view, by the way.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,当用户点击“完成”按钮时,不会调用 textFieldDidEndEditing。 一旦编辑后触摸任何内容,就会调用它。
为了拥有专用按钮“完成”,您可以创建一个完成键作为 UIBarButtonItem,并编写一个 IBAction,
如下所示:返回键。
您可以检查 TextFieldDidEndEditing 中是否按下了 Done 键...您也可以使用另一个按钮,然后返回它。
Firstly, the textFieldDidEndEditing is called not when the user taps the DONE button. It is called as soon as you touch anything after editing.
For having an exclusive button 'Done' you can create a Done key as a UIBarButtonItem, and write an IBAction like
The following line assigns the Done key as the Return Key.
You can check if the Done key was pressed in the TextFieldDidEndEditing...You may also use another button, and return it instead.
每当按下 Return 键时,UITextField 的实例都会向其委托发送一条
textFieldShouldReturn:
消息。如果您希望控制器接收此消息,请让它向文本字段发送setDelegate:
消息,并传递self
作为参数(或将文本字段的委托出口连接到Interface Builder 中的控制器)并在控制器类中实现以下方法:请参阅
UITextFieldDelegate
协议的文档以获取更多信息。An instance of UITextField will send a
textFieldShouldReturn:
message to its delegate whenever the Return key is pressed. If you want your controller to receive this message, have it send asetDelegate:
message to the text field, passingself
as the argument (or connect the text field's delegate outlet to the controller in Interface Builder) and implement the following method in your controller class:See the documentation for the
UITextFieldDelegate
protocol for further information.