gpt4 book ai didi

ios - UITextField 文本更改事件

转载 作者:IT老高 更新时间:2023-10-28 12:12:13 29 4
gpt4 key购买 nike

如何检测文本字段中的任何文本更改?委托(delegate)方法 shouldChangeCharactersInRange 适用于某些东西,但它并不能完全满足我的需要。因为在它返回 YES 之前,其他观察者方法无法使用 textField 文本。

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

他们有什么方法可以得到 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;
}

最佳答案

来自 proper way to do uitextfield text change call back :

I catch the characters sent to a UITextField control something like this:

// Add a "textFieldDidChange" notification method to the text field control.

在 Objective-C 中:

[textField addTarget:self 
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];

在 swift 中:

textField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)

Then in the textFieldDidChange method you can examine the contents of the textField, and reload your table view as needed.

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

关于ios - UITextField 文本更改事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7010547/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com