How to move UITextField cursor to next text field

I have three text fields, and I want to be able to move the cursor to the next. When the latter is reached, the keyboard is rejected. But nothing works for me ... Here is an example of what I have. However, nothing happens and nothing happens when I select the next button.

- (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; } 
+7
source share
1 answer

The object associated with this method must be set as a delegate to the text field. Test this by setting a breakpoint in the method to make sure that it is called when you think.

If you use tips or storyboards, the field... instance variables must be points that are correctly connected. If they are created programmatically, you must make sure that they have objects assigned to them. Check this by checking the values โ€‹โ€‹of these variables when you are inside the method.

You do not need to call resignFirstResponder on other controls until you call becomeFirstResponder on another.

+3
source

All Articles