UIControlEventEditingChanged不会触发时使用setText的UITextfield
问题说明
我目前正在尝试跟踪文本字段的状态。
I am currently trying to track the states of a textfield.
我使用自定义的datePicker通过设置文本-setText
I am using a custom datePicker which sets the text via -setText
[self.textField setText:[self.dateFormatter stringFromDate:self.date]];
在我的 textFieldDelegate 里面,我使用下面几行代码:
Inside my textFieldDelegate i use the following lines of Code :
....//viewDidLoad
self.travelToOnTextField.delegate = self;
[self.travelToOnTextField addTarget:self action:@selector(travelToOnTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; }
-(void)travelToOnTextFieldDidChange:(id)sender
{
NSLog(@"Event Handler called");
}
所以如果我通过自定义Datepicker改变文本方法 travelToOnDateTextFieldDidChange
不会调用。但如果我通过我的电脑键盘更改文本,它被调用。
So if i change the text via my custom Datepicker the Method travelToOnDateTextFieldDidChange
doesnt get called. But if i change the text via my Computer Keyboard it gets called.
Hack我做错了什么?
What the Hack i am doing wrong ?
正确答案
对此问题进行评分,因为这是重要的。
I had to rate this question up because this is super important.
这似乎在iOS6中已经改变。也许甚至iOS5。此事件已使用成为在UITextField中观察文本更改的首选方法。我从iOS3以来一直使用它。在iOS6上重新编译我的应用程序以执行一些更新后,它神秘地停止工作。我的应用程式的部分使用:
It appears this has changed in iOS6. Maybe even iOS5. This event USED to be the preferred method for observing text changes in a UITextField. I've been using it since iOS3. After recompiling my app on iOS6 to perform some updates, it mysteriously stopped working. Parts of my app use:
[UITextField insertText];
和其他人使用
[UITextField setText];
或
UITextField.text = @"xxx";
无论如何,请务必注意 setText strong>事件不再触发编辑已更改事件。如果你使用一个insertText方法,它仍然可以工作。
For whatever reason it's important to note that setText events no longer fire the Editing Changed event. If you use an insertText method, it still works.
所以如果你是一个绑定,你只需要一个快速修复,你可以更改你的代码:
So if you're in a bind and you just need a quick fix, you can change out your code from:
textField.text;
或
[textField setText:@"xxx"];
到
textField.text = @"";
[textField insertText:@"new text"];
这也有效:
[((UITextField*)view) sendActionsForControlEvents:UIControlEventEditingChanged];
我希望这可以帮助某人,因为我浪费了一整天试图找出为什么这个代码突然停止
I hope this helps someone, because I wasted an entire day trying to figure out why this code suddenly stopped working when I moved up to iOS6.
您仍然可以使用NSNotificationCenter。有关详情,请参阅UITextField参考:
You can still use NSNotificationCenter as well. See the UITextField reference for more info:
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfgegk
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
检查邮件是否发送成功
it1352 07-25 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22