How to dismiss the keyboard in iPhone


  • In the Interface Builder add the text field to the view and use the inspector to change the Text Input Traits so that the Return Key is set to Done (see thumbnail).Text Input Traits
  • In the .h file for your view controller, define an IBAction method to dismiss the keyboard, e.g.
    - (IBAction)dismissKeyboard:(id)sender;
  • In the .m file define the method:
    - (IBAction)dismissKeyboard:(id)sender {
    	[sender resignFirstResponder];
    }
    
  • In the Interface Builder, control click on the text field object, and connect the “Did End On Exit” event to the view controller’s File’s Owner object.

You can use the same method to dismiss the keyboard for all of the text fields in the view.

This technique no longer works in the latest version of IB (v3.2.1). Instead, you’ll need to connect the event “Did End of Exit” to the “First Responder” object in the “MainWindow.xib” and then select the “dismissKeyboard” method that you just introduced.

One Response to “How to dismiss the keyboard in iPhone”

  1. Mike Says:

    Thanks for your help. This Worked!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.