Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS app "next" key won't go to the next text field

I have a simple scene (using storyboard in IB) with a Username and Password text box. I've set the keyboard to close when you are on the Password text field but can't get the next(return) button to work on the Username to switch the focus (or First Responder) to the Password text box.

I'm closing the keyboard while on the Password text field like this:

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { if (theTextField == self.textPassword) {     [theTextField resignFirstResponder]; } return YES; } 

I know it is something similar to this but just can't nail it down.

like image 640
BamBamBeano Avatar asked Mar 02 '12 21:03

BamBamBeano


1 Answers

The return key doesn't do anything special in a text field by default. You need to explicitly change the first responder:

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {     if (theTextField == self.textPassword) {         [theTextField resignFirstResponder];     } else if (theTextField == self.textUsername) {         [self.textPassword becomeFirstResponder];     }     return YES; } 
like image 108
rob mayoff Avatar answered Sep 24 '22 14:09

rob mayoff