Graphics Programs Reference
In-Depth Information
<UINavigationControllerDelegate, UIImagePickerControllerDelegate ,
UITextFieldDelegate>
In DetailViewController.m , implement textFieldShouldReturn: .
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
It would be stylish to also dismiss the keyboard if the user taps anywhere else on De-
tailViewController 's view . We can dismiss the keyboard by sending the view
the message endEditing: , which will cause the text field (as a subview of the view )
to resign as first responder. Now let's figure out how to get the view to send a message
when tapped.
We have seen how classes like UIButton can send an action message to a target when
tapped. Buttons inherit this target-action behavior from their superclass, UIControl .
You're going to change the view of DetailViewController from an instance of
UIView to an instance of UIControl so that it can handle touch events.
In DetailViewController.xib , select the main View object. Open the identity in-
spector and change the view 's class to UIControl ( Figure 12.12 ) .
Figure 12.12 Changing the class of DetailViewController's view
Then, open DetailViewController.h in the assistant editor. Control-drag from the
view (now a UIControl ) to the method declaration area of DetailViewControl-
ler . When the pop-up window appears, select Action from the Connection pop-up menu.
Notice that the interface of this pop-up window is slightly different than one you saw
when creating and connecting the UIBarButtonItem . A UIBarButtonItem is a
simplified version of UIControl - it only sends its target an action message when it is
tapped. A UIControl , on the other hand, can send action messages in response to a
variety of events.
 
Search WWH ::




Custom Search