O'Reilly logo

iPad Application Development For Dummies, 3rd Edition by Neal Goldstein

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

Going to the Current Location

Although you require the user to pan to the user location on the map if he or she wants to see it, it’s kind of annoying in this particular case unless you’re actually coding this in or around New York City. To remove at least that annoyance from your life, I show you how easy it is to add a button to the Navigation bar to zoom in to the current location and then back to the map region and span you’re currently displaying.

Add the bolded code in Listing 17-21 to add the button in the MapController method viewDidLoad.

Listing 17-21: Updating viewDidLoad

- (void)viewDidLoad

{

[super viewDidLoad];

mapView.delegate = self;

mapView.showsUserLocation = YES;

[self setInitialRegion];

RTAppDelegate* appDelegate = [[UIApplication

sharedApplication] delegate];

if ([[UIDevice currentDevice] userInterfaceIdiom] ==

UIUserInterfaceIdiomPad) {

UILabel * titleLabel = [[UILabel alloc]

initWithFrame:CGRectMake (0,0,250,44)];

titleLabel.textColor = [UIColor yellowColor];

titleLabel.font = [UIFont boldSystemFontOfSize:17];

titleLabel.textAlignment = UITextAlignmentCenter;

titleLabel.backgroundColor = [UIColor clearColor];

titleLabel.text = [self mapTitle];

UIBarButtonItem *titleView = [[UIBarButtonItem alloc]

initWithCustomView:titleLabel];

UIBarButtonItem *flexibleSpace=

[[UIBarButtonItem alloc] initWithBarButtonSystemItem:

UIBarButtonSystemItemFlexibleSpace

target:nil action:nil];

flexibleSpace.width = 1.0;

NSMutableArray *itemsArray = ...

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