Search code examples
objective-ccocoa-touchios5

Go to next textfield when hit Return


I wrote a textFieldDone: method that's suppose to move the cursor to the next textfield when the Return button is tapped.

- (IBAction)textFieldDone:(id)sender {
     [nextTextField becomeFirstResponder];
     NSLog(@"in : textFieldDone");
}

I have connected the first textfield's "Did End On Exit" event to the File's Owner and chose the textFieldDone: method. I also assigned the File's Owner as the textfield's delegate (because I need the view to scroll up/down accordingly so the keyboard won't hide the textfields).

When I run the app on the simulator and tap the return button the first textfield resign first responder and in the log I see that the program didn't go through the textFieldDone: method, but it did go through the textFieldDidEndEditing: method.

I used that method before and had no problem.

Is it because the File's Owner is the textfield's delegate?


Solution

  • - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if ([textField isEqual:txt1]) 
        {
            [txt2 becomeFirstResponder];
        }
        return true;    
    }