UITextField文本更改事件

末鹿安然 提交于 2020-07-27 23:05:48

问题:

How can I detect any text changes in a textField? 如何检测textField中的任何文本更改? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly. 委托方法shouldChangeCharactersInRange可以为某些事情工作,但它不能完全满足我的需要。 Since until it returns YES, the textField texts are not available to other observer methods. 因为直到返回YES,否则textField文本不可用于其他观察者方法。

eg in my code calculateAndUpdateTextFields did not get the updated text, the user has typed. 例如,在我的代码中,用户已键入, calculateAndUpdateTextFields未获取更新的文本。

Is their any way to get something like textChanged Java event handler. 他们以任何方式获得诸如textChanged Java事件处理程序之类的东西。

- (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;
}

解决方案:

参考一: https://stackoom.com/question/TPlL/UITextField文本更改事件
参考二: https://oldbug.net/q/TPlL/UITextField-text-change-event
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!