Graphics Programs Reference
In-Depth Information
multi-line editing: a text view's return key enters the newline character whereas a text
field's return key dispatches the delegate method
textFieldShouldReturn:
.)
Putting the pieces together
To finish your
Whereami
application, you just need to add two final methods:
find-
Location
, which is sent in
textFieldShouldReturn:
, and
foundLocation:
,
which will be sent in
locationMan-
ager:didUpdateToLocation:fromLocation:
. In
WhereamiViewCon-
troller.h
, declare these two methods.
@interface WhereamiViewController : UIViewController
<CLLocationManagerDelegate, MKMapViewDelegate,
UITextFieldDelegate>
{
CLLocationManager *locationManager;
IBOutlet MKMapView *worldView;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UITextField *locationTitleField;
}
- (void)findLocation;
- (void)foundLocation:(CLLocation *)loc;
@end
The
findLocation
method will tell the
locationManager
to start looking for the
current location. It will also update the user interface so that the user can't re-enter text in-
to the text field and will start the activity indicator spinning. The
foundLocation:
method will create an instance of
BNRMapPoint
and add it to the
worldView
. It will
also handle the map's zoom and reset the states of the UI elements and the
loca-
tionManager
.
In
WhereamiViewController.m
, import
BNRMapPoint.h
and implement the two
methods.
#import "WhereamiViewController.h"
#import "BNRMapPoint.h"
@implementation WhereamiViewController
- (void)findLocation
{
[locationManager startUpdatingLocation];
[activityIndicator startAnimating];
[locationTitleField setHidden:YES];
}
- (void)foundLocation:(CLLocation *)loc