How do I programmatically set the Return Key for a particular UITextField?

I can’t believe that this question hasn’t been asked yet, but I have been unable to find it so that is my assumption.

I have created custom UITableViewCell subclasses using Interface Builder. These each contain a UILabel and a UITextField and are used for our login screen.

  • White space before separator line into my TableView
  • Drop down list ios swift
  • Find where object is retained with ARC
  • iPad 'dismiss keyboard' button doesn't dismiss keyboard
  • Xcode storyboard: Internal error. Please file a bug
  • How to set contents of scenekit background to cube map
  • On the first UITextField, I want the Keyboard Key to say Next. However, on the second UITextField, I want it to say “Done.”

    How do I programmatically change the value of the Return Key on the keyboard? I cannot use Interface Builder, since that would make both keys appear as Done.


    2 Solutions Collect From Internet About “How do I programmatically set the Return Key for a particular UITextField?”

    For the first UITextField, Read THIS tutorial on how to create a button on a Keyboard. You can learn the logic from there and use a Next button instead of Done button.

       //if you just want to make it appear NEXT//
        textField.returnKeyType = UIReturnKeyNext;

    And for the second UITextField, use…

       // for DONE //
        textField.returnKeyType = UIReturnKeyDone;

    You can in general create and rename the button to anything, and make sure you give the right IBAction on the event that that button is pressed. In case you do create your own custom button, look at the tutorial above to learn about placing it in the right coordinates and stuff.

    It can also be done by setting property in .xib file. You just have to set Return Key property of UITextField to Next under Attribute Inspector.