I've created this in my .h:
@interface Class : UIViewController <UITextFieldDelegate
And then in my .m:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == username) {
[textField resignFirstResponder];
}else if (textField == password) {
[textField resignFirstResponder];
}
return YES;
}
but when i try to run some code inside either the if for username or password it never gets run. I've tried to debug it, but when i tap on my text field it just opens the keyboard and it's not debugging. So it seems like textFieldShouldReturn never gets run, why?
Any help is much appreciated.
SOLUTION: Add: username.delegate = password.delegate = self; in your .m file
The purpose of textFieldShouldReturn: method is to determine if the text field should process the pressing of the return button on [virtual] keyboard.
I assume you are looking for textFieldShouldEndEditing: delegate method.
PS. I assume you have set password.delegate = username.delegate = self;