iOS文本字段不辞职第一响应者 [英] iOS text field not resigning first responder
本文介绍了iOS文本字段不辞职第一响应者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法为文本字段辞去第一响应者的职务.请帮忙,我在stackoverflow上查看了其他解决方案,但找不到解决方案.这是抛出的错误unrecognized selector sent to instance
I can't seem to resign first responder for text field. Please help and I have looked at other solutions on stackoverflow but can't find the solution. Here is the error thrown unrecognized selector sent to instance
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet var textInputScreen: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textInputScreen.delegate = self
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
// textField.canResignFirstResponder is true
textField.resignFirstResponder() // throws error
// view.endEditing(true) // throws same error
// textInputScreen.resignFirstResponder() // throws same error
return true
}
推荐答案
最常见的情况是您的 TextField 至少有一个不链接到任何内容的引用出口.如果您可以再次查看您的故事板,您可能会看到类似这样的内容.
The most common case is your TextField has at least one referencing outlet which does not link to anything. If you can take a look again at your storyboard, you might see something like this.
这篇关于iOS文本字段不辞职第一响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文