1

How to I go from one textfield to the next with the next button?

Here is my code that will not work:

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    if (theTextField == self.amountField) {
        [theTextField resignFirstResponder];
    } else if (theTextField == self.businessField) {
        [self.memoField becomeFirstResponder];
    }
    return YES;
}
  • Please have a look at http://stackoverflow.com/questions/992265/best-way-to-use-next-version-of-return-button-on-uitextfield-to-move-to-next-u – Jake Lin Sep 26 '14 at 01:09

2 Answers2

1

Call [textField resignFirstResponder]; before your first conditional

danh
  • 62,181
  • 10
  • 95
  • 136
Raymond Brion
  • 332
  • 1
  • 10
0

there are many solutions but I prefer this one:

[self.firstTextField addTarget:self.secondTextField action:@selector(becomeFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit];
[self.secondTextField addTarget:self.thirdTextField action:@selector(becomeFirstResponder) forControlEvents:UIControlEventEditingDidEndOnExit];

just set it up in viewDidLoad

Mobile Developer
  • 5,730
  • 1
  • 39
  • 45