Reputation: 1412
I have two classes. In one of them, the return key (for the virtual keyboard) works perfectly. In the other, it does not. As far as I can tell, the code is pretty much identical. Can someone help me figure out why my its not firing on the one that doesn't work?
This one works:
class ChangePasswordVC: UIViewController, UITextFieldDelegate {
func textFieldShouldReturn(textField: UITextField) -> Bool {
if textField == self.tempPasswordTextField {
self.changeTempPasswordTextField.becomeFirstResponder()
}
else if textField == self.changeTempPasswordTextField {
self.confirmChangeTempPasswordTextField.becomeFirstResponder()
}
else {
changePasssword()
}
return true
}
}
This one does not work:
class ResetPasswordVC: UIViewController, UITextFieldDelegate {
func textFieldShouldReturn(textField: UITextField) -> Bool {
if textField == self.emailTextField {
print("go button tapped")
submitEmailForPasswordReset()
}
return true
}
}
I put the print statement in to see if it fires at all but it doesn't print anything to the console.
Upvotes: 0
Views: 6175
Reputation: 887
You have to set UITextField delegate either using StoryBoard/XIB or using code. It will work fine when UITextField delegate assigned correctly.
Upvotes: 1
Reputation: 35382
You have forgot probably some of the delegate settings, check for:
self.tempPasswordTextField.delegate = self
self.changeTempPasswordTextField.delegate = self
self.confirmChangeTempPasswordTextField.delegate = self
self.emailTextField.delegate = self
In your code especially check the last (self.emailTextField
).
Upvotes: 15