Sunday, 13 March 2011

Hide Keyboard on Text Field Return - iPhone, iPad, iOS Development

One of the most asked question's by new iPhone developers is how to hide the keyboard. This is certainly one of the most lacking area's of the documentation for a budding iPhone developer.

To programatically hide the keyboard you must call the method resignFirstResponder on your text field or text view. This can be called from anywhere however it is most commonly from a done button or from the keyboard return key being pressed.
  [textField resignFirstResponder];
To hide the keyboard when the return key is pressed you must add a listener to the text field (UITextField) delegate method. UITextfieldDelegate protocol contains a method called textFieldShouldReturn, This method is called to determine if the text field should process the pressing of the return key. You can call your resignFirstResponder on the text field from within this method to hide the keyboard when pressed.

 - (BOOL)textFieldShouldReturn:(UITextField *)textField {
[
textField resignFirstResponder];
}


If this doesn't appear to be working for you make sure you've remembered to set the delegate property on the textField.

If you have any problems feel free to post in the comment's ;)

15 comments:

  1. If my component is a Multiline TextField? The Return button would take the keyboard off istead break the line?

    ReplyDelete
  2. Hello,
    They have experienced game developers who know each and every tricks and tweaks of the game development market.

    Hire iphone Developer

    ReplyDelete
  3. I have recently started Iphone Application Developmentt and this is really a new concept for me. I have understood the code and now trying to implement this in my project.

    ReplyDelete
  4. iPhone Development
    has become very important for the companies working on various mobile development platforms. With the iPhone SDK available, mobile developers can now build new apps and also customize the existing ones.

    ReplyDelete
  5. Hey, I created a view controller which does everything automatically. Have a look here: http://www.iosissues.com/2012/12/how-to-hide-keyboard-when-return-button.html

    ReplyDelete
  6. Great idea !
    using web technologies is not "easy" you can get errors and problems however the advantages of using web technologies to create your gaming website outweigh the cons.

    iphone apps development

    ReplyDelete
  7. Iphone Development has brought a revolution in mobile computing. There is no doubt that any company not thinking about developing their apps related to its industry will not be left behind.

    ReplyDelete
  8. I am dreadfully thankful to all of your team for sharing such motivating information.

    iPhone developer in Pakistan

    ReplyDelete
  9. iOS8 features also embraces predictive typing for Apple’s QuickType console; Family Sharing is also an amazing feature which is the easiest way to share photos and calendars within the same home; and iCloud Drive, so the privileged user can store files and can have access on them from anywhere.

    ReplyDelete
  10. Great article.I like your thoughts and it's really great.Great discussion.Thanks for sharing.
    --------------------------------------------------------------------------------------------------------------
    iPhone App Development

    ReplyDelete

  11. Thanks for posting useful information.You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...Really it was an awesome article...very interesting to read..
    please sharing like this information......
    Android training in chennai
    Ios training in chennai

    ReplyDelete
  12. ” Wow, marvelous blog layout! How long have you ever been blogging for? you make running a blog look easy The full glance of your site is magnificent, let alone the content! “

    iPhone App Develoment Company

    ReplyDelete
  13. It is really a great work and the way you sharing the knowledge is excellent.
    As a beginner in iPhone App Development your post is very help full. Thanks for your informative article. If you guys interested to learn iPhone App Development.
    iPhone app development perth

    ReplyDelete