O'Reilly logo

Xcode 4 iOS Development by Steven F. Daniel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – hiding the keyboard

In the case of our Username text field, we could resign its first responder status and get rid of the keyboard by adding the following line of code to our HelloXcode4_GUIViewController.m file:

[txtUsername resignFirstResponder];

Calling the resignFirstResponder method tells the input object to give up its claim to the input control, hence the keyboard disappears.

There is a second common method for hiding the keyboard in iOS applications through the Did End on Exit event of the field. This event occurs when the return or done keyboard button is pressed.

To add keyboard hiding to our HelloXcode4_GUI application, follow these steps:

  1. Switch back to our application in Xcode and create the action declaration for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required