Changes

Jump to: navigation, search

Writing Code to Hide the iPhone Keyboard

139 bytes added, 13:49, 29 July 2010
Hiding the Keyboard when the User Taps the Background
@end
</pre>
 
Save the ''hideKeyboardViewController.h'' before proceeding.
Next, open the ''hideKeyboardViewController.m'' file and implement the action by calling the resignFirstResponder method of our textField object:
</pre>
Once the changes have been made, be sure to save the file before proceeding. Having written the code for our action method we now need to make sure it gets called when the user touches the background view. This involves some work in Interface Builder, so double click on the hideKeyboardViewController.xib file to invoke the tool.
In order to make the keyboard disappear we need to configure our user interface so that the action method gets called when the background view is touched by the user. By default, Interface Builder has given us an instance of the UIView class as the background to our interface. Unfortunately UIView instances are unable to respond to events so there is no way given the current configuration that we can trigger our action method. We must, therefore, change the class of the view to be an instance of the UIControl class. In the ''hideKeyboardViewController.xib'' window there is an icon labeled View located to the right of the ''File’s Owner'' and ''First Responder'' icons. This represents the main view of our interface. Select this icon and display the Identity Inspector (''Tools -> Identity Inspector'' or Command+4) and within the inspector window change the Class setting from UIView to UIControl:

Navigation menu