mhbdr
mhbdr

Reputation: 753

iOS - Change a ViewController with the keyboard "next" button?

I've noticed it's possible to trigger actions and to move through text fields using the done/next/return key in the bottom right of the iOS keyboard. Would it be possible to maybe change a view or trigger a segue with that button?

For example, it would be cool to be able to type something into a UITextField, and then just tap "Next" to move onto the next viewController instead of having to use a separate button, or navigation item.

May be a stupid question, but something that I've been wondering if it was possible for a while.

Upvotes: 0

Views: 1299

Answers (2)

danh
danh

Reputation: 62686

It is possible. If it's a UITextField, you can implement textFieldShouldReturn:. If it's a UITextView, you implement textView:shouldChangeTextInRange:replacementText:, and look for \n in the replacement text.

In either case, you can then perform a segue, do a navigation or modal push, etc.

Upvotes: 1

shabbirv
shabbirv

Reputation: 9098

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //Next button was pressed
    //Push some viewcontroller here
    return YES;
}

make sure you set the delegate of the UITextField to self

Upvotes: 1

Related Questions