iPhone Keyboard automatically move to next textfield when Next is pressed



In order to move the cursor automatically to the next data entry field when the user presses Next on the keyboard you need to resignFirstResponder from the current field and assign it to the next field using becomeFirstResponder

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	if (textField == field1TextField) {
		[textField resignFirstResponder];
		[field2TextField becomeFirstResponder];
	} 
	else if (textField == field2TextField) {
		[textField resignFirstResponder];
		[field3TextField becomeFirstResponder];
	}
	else if (textField == field3TextField) {
		[textField resignFirstResponder];
	}
	return YES;
}


You need to set the Return Key types accordingly within the interface builder. Your ViewController must also implement UITextFieldDelegate and the textfields delegate assignment must be set via IB to the File’s Owner

See what I do

6 Responses to “iPhone Keyboard automatically move to next textfield when Next is pressed”

  1. Thank you!

  2. Thanks! Simple and clear :)

  3. thanky also from my side :)

  4. Is there a way to automatically move the cursor to the next object without having to press next or enter? For instance-
    When the user enters one letter into a text field, how do I make it automatically move to the another object without the user having to do anything else?

    Thanks!

  5. Thanks its working i was in searching of this and great simple logic

  6. Hi, you should be able to use the same sort of logic, i.e. resignResponder and becomeFirstResponder in the method

    -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text