user3806600
user3806600

Reputation: 49

UITextField - Next Button

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;
}

Upvotes: 1

Views: 237

Answers (2)

Mobile Developer
Mobile Developer

Reputation: 5760

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

Upvotes: 0

Raymond Brion
Raymond Brion

Reputation: 332

Call [textField resignFirstResponder]; before your first conditional

Upvotes: 1

Related Questions