UITextField“值已更改”字段更新时不触发 [英] UITextField "value changed" not firing when field is updated

查看:114
本文介绍了UITextField“值已更改”字段更新时不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 IBAction 我已经连接到Interface Builder中的 UITextField 元素。 (在值已更改事件中出场)

I have an IBAction that I have connected to a UITextField element in Interface Builder. (Firing on "value changed" event)

我还有一个 UISlider ,它会自动更新TextField元素价值得到调整。

I also have a UISlider that updates the TextField element automatically when it's value gets adjusted.

当我运行我的应用程序时,我调整滑块时TextField会更新,但发生这种情况时值已更改事件不会触发。当我手动编辑TextField时,也不会触发值更改事件。 (虽然使用Did Editing End触发器确实会触发它。)

When I run my app, the TextField does get updated when I adjust the slider, but the "value changed" event does not fire when this happens. The value changed event also does not fire when I edit the TextField by hand as well. (Although using the Did Editing End trigger does cause it to fire).

我的问题是,如何获取值更改触发器以进行程序化更新TextField以及用户调整值时。

My question is, how can I get the value changed trigger to fire for both a programmatic update of the TextField as well as when the user adjusts the value.

推荐答案

根据TheRonin的建议,使用 UITextFieldDelegate 并实现以下方法

As suggested by TheRonin, use UITextFieldDelegate and implement the following method

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

这篇关于UITextField“值已更改”字段更新时不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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