处理“完成” textViewDidEndEditing 外部键盘上的按钮

发布于 2024-11-14 13:45:03 字数 169 浏览 2 评论 0原文

当按下“完成”时,我知道 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

话少情深 2024-11-21 13:45:04

首先,当用户点击“完成”按钮时,不会调用 textFieldDidEndEditing。 一旦编辑后触摸任何内容,就会调用它。

为了拥有专用按钮“完成”,您可以创建一个完成键作为 UIBarButtonItem,并编写一个 IBAction,

- (IBAction) doneClicked:(id)sender 

如下所示:返回键。

textField.returnKeyType = UIReturnKeyDone;

您可以检查 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

- (IBAction) doneClicked:(id)sender 

The following line assigns the Done key as the Return Key.

textField.returnKeyType = UIReturnKeyDone;

You can check if the Done key was pressed in the TextFieldDidEndEditing...You may also use another button, and return it instead.

水中月 2024-11-21 13:45:03

每当按下 Return 键时,UITextField 的实例都会向其委托发送一条 textFieldShouldReturn: 消息。如果您希望控制器接收此消息,请让它向文本字段发送 setDelegate: 消息,并传递 self 作为参数(或将文本字段的委托出口连接到Interface Builder 中的控制器)并在控制器类中实现以下方法:

- (BOOL)textFieldShouldReturn:(UITextField *)textField;

请参阅 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 a setDelegate: message to the text field, passing self 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:

- (BOOL)textFieldShouldReturn:(UITextField *)textField;

See the documentation for the UITextFieldDelegate protocol for further information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文