Ios – How to 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.

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.


Best Solution

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.