所以我做了这个函数,当2个文本字段达到最小数量的文本计数时触发,将使按钮被启用。
它可以在iOS13和更高版本上运行,但不能在ios 12....which上运行。我不知道它是如何运行的,也不知道为什么它不运行。
所以基本上,当我在我的textfield.....its上打字时,我的textFieldDidChangeSelection不会触发任何东西,它不能在iOS12上工作,但它能在13和以上系统上工作
我试着在textFieldDidChangeSelection上打印一些东西,但是控制台上什么都没有打印出来
这是我的代码
//这是我的函数代码
func buttonReady() {
if phoneNumberTextField.text!.count > 8 && textPinTextField.text!.count == 6{
loginButton.isUserInteractionEnabled = true
loginButton.backgroundColor = UIColor.init(string: COLOR_RED)
loginButton.setTitleColor(UIColor.white, for: .normal)
print("ahaaaa ??")
} else {
loginButton.isUserInteractionEnabled = false
loginButton.backgroundColor = UIColor.init(string: COLOR_GREY_BUTTON)
loginButton.setTitleColor(UIColor.init(string: COLOR_GREY_TEXT), for: .normal)
print("hmmmm ?")
}
}我在这里使用了这个函数
func textFieldDidChangeSelection(_ textField: UITextField) {
if textField == phoneNumberTextField {
buttonReady()
}
if textField == textPinTextField {
buttonReady()
}
}还有这里
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
buttonReady()
hideKeyboardWhenTappedAround()
}在我的自定义文本字段中使用SkyFloatingLabelTextFIeld
我仍然不明白为什么这个函数不能在ios12上工作,而它在iOS13和更高版本上工作
发布于 2021-03-10 11:23:05
同样的问题
你可以试试这个
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
phoneNumberTextField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
textPinTextField.addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged)
buttonReady()
hideKeyboardWhenTappedAround()
}比
@objc func textFieldDidChange() {
buttonReady()
}发布于 2021-04-16 00:45:08
查看UITextField.h,您将看到:
- (void)textFieldDidChangeSelection:(UITextField *)textField API_AVAILABLE(ios(13.0), tvos(13.0));textFieldDidChangeSelection仅在iOS 13.0和更高版本上可用。
https://stackoverflow.com/questions/66419691
复制相似问题