简体   繁体   中英

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.

- (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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM