问题:
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
来源:oschina
链接:https://my.oschina.net/u/3797416/blog/4285703