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
Written by Paul Ledger
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#