Graphics Programs Reference
In-Depth Information
In WhereamiViewController.h , declare that WhereamiViewController con-
forms to the UITextFieldDelegate protocol.
@interface WhereamiViewController : UIViewController
<CLLocationManagerDelegate, MKMapViewDelegate ,
UITextFieldDelegate>
{
In WhereamiViewController.m , implement textFieldShouldReturn: .
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// This method isn't implemented yet - but will be soon.
[self findLocation];
[textField resignFirstResponder];
return YES;
}
For now, ignore findLocation . You will write the implementation for that in a mo-
ment. First, let's talk about text editing and the first responder . UIResponder is a class
in the UIKit framework. A responder is responsible for receiving and handling events that
are associated with it. UIView is a subclass of UIResponder . Therefore, UIView ob-
jects can receive events. A button is a responder that handles touch events, like a tap.
Shaking a device and tapping a key on the keyboard also generate events.
One of the responders is the first responder . Only one responder can be the first responder
at a time. The first responder handles events that aren't associated with a position on the
screen. For instance, a tap is sent to the view object that was tapped, but shaking the
device has no position on the screen, so that event is sent to the first responder instead.
We'll talk more about the first responder and event-handling in Chapter 6 and Chapter 19 .
For now, let's focus on UITextField . A UITextField is also a responder: it is a dir-
ect subclass of UIControl , which is a subclass of UIView , which is a subclass of
UIResponder . When a UITextField is tapped, it handles this event by becoming the
first responder.
When a UITextField becomes the first responder, a keyboard automatically appears
on the screen. To remove the keyboard from the screen, you tell the UITextField to
give up its first responder status by sending it the message resignFirstResponder .
Once the first responder is no longer a UITextField , the keyboard will disappear.
(Everything about UITextField holds true for the class UITextView , too. The dif-
ference between UITextView and UITextField is that UITextView allows for
Search WWH ::




Custom Search