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 ;)

12 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. Great article.I like your thoughts and it's really great.Great discussion.Thanks for sharing.
    --------------------------------------------------------------------------------------------------------------
    iPhone App Development

    ReplyDelete
  9. 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
  10. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    best ios training institute
    ios training institute
    ios training institute in hyderabad

    ReplyDelete
  11. Much obliged for sharing this great substance. it's exceptionally helpful to us. I acquired a ton of data, the manner in which you have obviously clarified is truly phenomenal. You rock for this blog.
    Empower your Business with ReactJS Development

    ReplyDelete