gpt4 book ai didi

ios - textFieldShouldBeginEditing 被错误的文本字段触发

转载 作者:行者123 更新时间:2023-11-29 00:30:15 26 4
gpt4 key购买 nike

我有两个文本字段 dateNTextFieldprenomTextField,其中仅设置了 dateNTextField 的委托(delegate):

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField.tag == self.dateNTextField.tag {
print(textField.tag)
self.view.endEditing(true)
}
return true
}

但是,即使两个文本字段具有不同的标签,我也会得到相同的结果!任何帮助将不胜感激。

编辑:

override func viewDidLoad()
{
self.dateNTextField.delegate = self
let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:#selector(chooseImage(recognizer:)));
self.picker.delegate = self
profilImage.isUserInteractionEnabled = true
profilImage.addGestureRecognizer(tapGestureRecognizer)
tapGesture.cancelsTouchesInView = true
self.view.addGestureRecognizer(tapGesture)
tapGesture.delegate = self
self.dateNTextField.accessibilityIdentifier = "date"
self.prenomTextField.accessibilityIdentifier = "prenom"}

最佳答案

尝试将 return true 语句放在 if 条件中。

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
if textField == self.dateNTextField{
self.view.endEditing(true)
return true
}
return false
}

关于ios - textFieldShouldBeginEditing 被错误的文本字段触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42068377/

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