2

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;
    }
Venk
  • 5,949
  • 9
  • 41
  • 52
Praveen R.
  • 241
  • 4
  • 15
  • I have also just tried: self.login.delegate = self; self.password.delegate = self; still doesn't work – Praveen R. Jul 07 '11 at 22:31
  • Figured it out, I'm new to iphone development, so this may be obvious to most of you. I didn't create a connection emanating from my file owner to the text fields - I thought they only had to be done the other way around. – Praveen R. Jul 08 '11 at 00:20

1 Answers1

0

From the code that you've posted, it does not appear to me that you have declared the outlets in your header:

IBOutlet UITextField *login;
IBOutlet UITextField *password;

Be sure to declare them and set up the connections in the IB.

PengOne
  • 48,188
  • 17
  • 130
  • 149