手动设置“文本"对于 UITextField 不调用 .EditingChanged [英] Manually setting "text" for a UITextField does not call .EditingChanged
本文介绍了手动设置“文本"对于 UITextField 不调用 .EditingChanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经继承了具有目标的 UITextField
I have subclassed UITextField which has the target
self.addTarget(self, action: "onChange:", forControlEvents: .EditingChanged)
当用户在文本字段中输入时,这可以正常工作.尽管我需要在手动更新文本字段的text"属性时调用相同的方法onChange:".
This works fine when the user is typing in the textfield. Although I would need to the same method "onChange:" to be called when the textfield's "text" property is manually updated.
let tf = CustomTextField()
tf.text = "Trigger !!!"
我怎么能这样做?
推荐答案
这是故意的,如果您需要在事件处理程序中以编程方式更改文本,可以防止无休止的回声.
This is intentional, to prevent endless echo if you need to change the text programmatically in an event handler.
使用 sendActions(for controlEvents:)
手动通知事件处理程序.
Use sendActions(for controlEvents:)
to manually notify event handlers.
tf.text = "Trigger !!!"
tf.sendActions(for: .editingChanged)
这篇关于手动设置“文本"对于 UITextField 不调用 .EditingChanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文