gpt4 book ai didi

ios - 如何检查 UITextField 何时更改?

转载 作者:行者123 更新时间:2023-11-28 07:19:58 25 4
gpt4 key购买 nike

我正在尝试检查文本字段何时更改,这也等同于用于 textView 的函数 - textViewDidChange 到目前为止我已经这样做了:

  func textFieldDidBeginEditing(textField: UITextField) {
if self.status.text == "" && self.username.text == "" {
self.topRightButton.enabled = false
} else {
self.topRightButton.enabled = true
}
}

哪种类型的作品,但 topRightButton 在按下文本字段后立即启用,我希望它仅在实际输入文本时启用?

最佳答案

SWIFT

swift 4.2

textfield.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), for: .editingChanged)

@objc func textFieldDidChange(_ textField: UITextField) {

}

SWIFT 3 和 swift 4.1

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

func textFieldDidChange(_ textField: UITextField) {

}

SWIFT 2.2

textField.addTarget(self, action: #selector(ViewController.textFieldDidChange(_:)), forControlEvents: UIControlEvents.EditingChanged)

func textFieldDidChange(textField: UITextField) {
//your code
}

objective-C

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

和 textFieldDidChange 方法是

-(void)textFieldDidChange :(UITextField *) textField{
//your code
}

关于ios - 如何检查 UITextField 何时更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58491641/

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