Reputation: 10520
I have a custom view that displays a list of words that are entered from the UITextField.
For easy and quick input, I intended to not hide keyboard after return key is pressed but instead I reset the text field and let user continue on typing more words. I need to hide keyboard when user is done with entering words, meaning when user taps outside the text field.
But the following implementation gives me uncaught exception when taps outside the text field.
I wonder if empty string checking associated with resignFirstResponder() is causing this but I need to make sure if the field is holding some values.
I think self.endEditing(true)
is not relevant to my situation as there is no way to know when user wants to end editing unless tap outside the textfield.
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
textField.returnKeyType = UIReturnKeyType.Done
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
textField.resignFirstResponder()
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
if let text = textField.text {
addTextToList()
}
textField.text = ""
return true
}
The uncaught exception is
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CookMate.CreateRecipeVC ingredientTextFieldDidChange:]: unrecognized selector sent to instance 0x7f80f1de3370'
Upvotes: 0
Views: 626
Reputation: 5188
Did you establish an outlet via Storyboard that you then later deleted named ingredientTextFieldDidChange
? Right click on the textField
in Storyboard to see if that exists, then press the x
to delete it.
Upvotes: 2