当所述改变不是由所述键盘进行时,检测所述UITextField的内容的改变 [英] detecting the change of content of UITextField when the change is not made by the keyboard
本文介绍了当所述改变不是由所述键盘进行时,检测所述UITextField的内容的改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 UIButton
和 UITextField
,当按下按钮时,textfield的内容字符串将等于:这是一个测试字符串
,在这种情况下如何检测到此文本字段已更改其内容?
I have a UIButton
and a UITextField
,when the button is pressed the textfield's content string will be equal to: This is a test string
, how can I detect that this text field has changed its contents in this case?
ps UITextField的
委托方法不适用于这种情况
p.s. UITextField's
delegate methods do not work in such case
UPDATE:
推荐答案
也许简单 键值观察 工作?
Maybe simple key-value observing will work?
[textField addObserver:self forKeyPath:@"text" options:0 context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if([keyPath isEqualToString:@"text"] && object == textField) {
// text has changed
}
}
编辑:我只是检查它,它适用于我。
I just checked it, and it works for me.
这篇关于当所述改变不是由所述键盘进行时,检测所述UITextField的内容的改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文