按下另一个按钮时,执行当前的UITextField自动更正建议 [英] Execute current UITextField autocorrect suggestion when another button is pressed
问题描述
我正在我的应用程序中实现聊天,非常类似于iPhone的内置消息应用程序。我在按钮旁边有一个UITextField。用户在文本字段中键入内容,并且文本字段通常表示各种自动更正。在内置的消息应用程序中,点击发送按钮将导致当前可见的自动更正建议执行。我在我的应用程序中寻找此行为,但无法找到任何内容。
I am implementing chat in my application, very similar to the iPhone's built-in Messages app. I have a UITextField next to a button. The user types something into the text field, and very often the text field suggests various autocorrections. In the built-in Messages app, tapping the Send button will cause the currently visible autocorrection suggestion to execute. I am seeking this behavior in my application, but haven't been able to find anything.
有没有人知道以编程方式执行当前可见的自动更正/自动完成建议的方法一个完全独立的控件被激活时的UITextField?这显然是可能的。
Does anyone know of a way to programmatically execute the currently visible autocorrection/autocomplete suggestion of a UITextField when a completely separate control is activated? It's obviously possible somehow.
推荐答案
在字段上调用 -resignFirstResponder
。这迫使它接受自动更正。如果您不想关闭键盘,可以立即再次调用 -becomeFirstResponder
。
Call -resignFirstResponder
on the field. That forces it to accept the autocorrect. If you don't want to dismiss the keyboard, you can immediately follow that with a call to -becomeFirstResponder
again.
这篇关于按下另一个按钮时,执行当前的UITextField自动更正建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!