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 one. When the last one is reached, the keyboard dismisses. But nothing works for me... Here's an example of what I have. However, nothing moves, 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;
}
The object that this method is bound to should be set as the text field's delegate. Check this by setting a breakpoint in the method to verify that it is called when you think it is.
If you are using nibs or storyboards, the field...
instance variables should be outlets that are correctly hooked up. If they are created programmatically, you should ensure that they have objects assigned to them. Verify this by inspecting the values of these variables when you are inside the method.
You don't have to call resignFirstResponder
on other controls before calling becomeFirstResponder
on another.
上一篇: C ++代码中的双重否定