Last Updated: January 28, 2019
·
20.36K
· flexicoder

Moving to the next UITextField in an iOS App

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

http://www.flexicoder.com/blog/index.php/2009/08/iphone-keyboard-automatically-move-to-next-textfield-when-next-is-pressed/