UITextField文本更改事件 [英] UITextField text change event
问题描述
如何检测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;
}
推荐答案
我捕获发送到UITextField控件的字符,如下所示:
I catch the characters sent to a UITextField control something like this:
// Add a "textFieldDidChange" notification method to the text field control.
[textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
然后在textFieldDidChange:方法中,您可以检查textField的内容,并根据需要重新载入您的表视图。
Then in the textFieldDidChange: method you can examine the contents of the textField, and reload your table view as needed.
您可以使用它,并将 calculateAndUpdateTextFields 作为 selector
。
You could use that and put calculateAndUpdateTextFields as your selector
.
这篇关于UITextField文本更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!