UITextField文本更改事件

UITextField文本更改事件

本文介绍了UITextField文本更改事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测textField中的任何文本更改?委托方法 shouldChangeCharactersInRange 适用于某些东西,但是它并没有完全满足我的需要。由于直到它返回YES,textField文本不适用于其他观察器方法。

How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly. Since until it returns YES, the textField texts are not available to other observer methods.

例如在我的代码 calculateAndUpdateTextFields 中没有获得更新的文本,用户已输入。

e.g. in my code calculateAndUpdateTextFields did not get the updated text, the user has typed.

他们有任何方式获取类似于 textChanged Java事件处理程序的东西。

Is their any way to get something like textChanged Java event handler.

- (BOOL)textField:(UITextField *)textField
            shouldChangeCharactersInRange:(NSRange)range
            replacementString:(NSString *)string
{
    if (textField.tag == kTextFieldTagSubtotal
        || textField.tag == kTextFieldTagSubtotalDecimal
        || textField.tag == kTextFieldTagShipping
        || textField.tag == kTextFieldTagShippingDecimal)
    {
        [self calculateAndUpdateTextFields];

    }

    return YES;
}


推荐答案

从:



// Add a "textFieldDidChange" notification method to the text field control.
[textField addTarget:self
              action:@selector(textFieldDidChange:)
    forControlEvents:UIControlEventEditingChanged];



您可以使用它,并将 calculateAndUpdateTextFields 作为 selector

You could use that and put calculateAndUpdateTextFields as your selector.

这篇关于UITextField文本更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 02:28