Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Move UITextField Cursor to Next Text Field [closed]

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;
}
like image 475
Kyle Greenlaw Avatar asked Apr 06 '13 00:04

Kyle Greenlaw


1 Answers

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.

like image 51
Jim Avatar answered Nov 14 '22 15:11

Jim