- 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).
- 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.
June 7, 2009 at 9:27 pm |
Thanks for your help. This Worked!!!