Search code examples
iphoneobjective-ctextfieldbecomefirstresponderresignfirstresponder

After becomeFirstResponder textField doesn't send events to delegate


can anybody help me in such situation:

I have SigninController class with two textFields (as Outlets) txtLogin and txtPassword:

when I filled txtLogin, I call [txtPassword becomeFirstResponder] to pass input focus to next field (return button works fine in txtLogin), but Return button doesn't work in txtPassword and I can't dismiss keyboard in this case. What did I write wrong ?

Example code:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == txtLogin) {
        [txtLogin resignFirstResponder];      //Works as I think
        [txtPassword becomeFirstResponder];   // txtPassword gets focus
    } else {
        [self signinClick];  //Never enter here
    }
    return YES;
}


- (IBAction)signinClick
{
    NSLog(@"Signin Clicked");
    [activityIndicator startAnimating];
    [txtPassword resignFirstResponder];
    ..........
}

Solution

  • It seems you have forgot to set the delegate of txtPassword correctly.