iOS text field not resigning first responder

我只是一个虾纸丫 提交于 2019-12-13 19:07:41

问题


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
    }

回答1:


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.



来源:https://stackoverflow.com/questions/45317500/ios-text-field-not-resigning-first-responder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!