I have the following code below, and I can't figure out why the textFieldShouldReturn
method is not being called. When I use IB to create the connection to the delegate, it works, but when done programmatically, the log statement is not being displayed. What am I doing wrong here?
Secondly, in the textFieldShouldReturn
, some examples return YES
, and some return NO
. The ios documentation specified that returning YES
would provide default implementation. Can someone please explain this in more detail?
//.h
file
@interface GoSocietyLoginController : UIViewController <UITextFieldDelegate> {
}
- (IBAction)textFieldDoneEditing:(id)sender;
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
@end
//.m
file
@interface GoSocietyLoginController ()
@property (nonatomic,retain) IBOutlet UITextField *login;
@property (nonatomic,retain) IBOutlet UITextField *password;
@end
@implementation GoSocietyLoginController
@synthesize login;
@synthesize password;
- (void)viewDidLoad
{
[super viewDidLoad];
[login setDelegate:self];
[password setDelegate:self];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"Hello World");
if ([textField isEqual:login]) {
[password becomeFirstResponder];
}
return NO;
}