Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.

Thanks!

like image 454
TigerTrussell Avatar asked Jun 10 '11 19:06

TigerTrussell


People also ask

What is UITextField?

An object that displays an editable text area in your interface.

How do I activate the return button on my iPhone?

Tap “123” key in the bottom-left corner of the keyboard. 2. The Return key is located in the bottom-right corner, next to the space bar.


2 Answers

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.

like image 55
Legolas Avatar answered Sep 29 '22 11:09

Legolas


you have to invoke [textView reloadInputViews]; after setting the return key type to update the keyboard return key appearance immediately.

DO IT AS FLLOW:

textView.returnKeyType = UIReturnKeyDone; [textView reloadInputViews];

like image 30
Quanhua Guan Avatar answered Sep 29 '22 09:09

Quanhua Guan