问题
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