UIControlEventEditingChanged不会触发时使用setText的UITextfield [英] UIControlEventEditingChanged doesnt get fired when using setText of UITextfield

查看:1447
本文介绍了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:

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html

这篇关于UIControlEventEditingChanged不会触发时使用setText的UITextfield的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆