Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

iphone - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...