Datasheet

756
Adding Some Code to Actually Add Some Functionality
Listing 1-3 (continued)
//addHotelController.delegate = self;
[self presentModalViewController:navigationController
animated:YES];
[navigationController release];
[addHotelController release];
Annotation *annotation = [NSEntityDescription ins
ertNewObjectForEntityForName:@”Annotation”
inManagedObjectContext:trip.managedObjectContext]; //$$
[annotation setTitle:@”Annotation”];
[annotation setHotel:hotel];
[hotel setAnnotation:annotation];
Geocoder * geocoder = [[Geocoder alloc] init];
NSString* geocodeString = [[NSString alloc ]
initWithFormat: @” %@ %@ %@ %@”, hotel.street, hotel.city,
hotel.state, hotel.zip];
NSLog (@” finding = %@”, geocodeString);
CLLocationCoordinate2D theCoordinate = [geocoder
geocodeLocation:geocodeString];
hotel.annotation.latitude = [NSNumber numberWithDouble:
theCoordinate.latitude];
hotel.annotation.longitude = [NSNumber numberWithDouble:
theCoordinate.longitude];
hotel.annotation.title = hotel.name;
}
Most of this code is pretty straightforward. This is the way you created view
controllers in the tableView:didSelectRowAtIndexPath: methods
in both the SightListController and RootViewController back in
Books V and VI. In this case, however, you’re using presentModalView
Controller.
Modal view controllers are used in applications to allow the user to enter
the information it needs. A modal view controller is not a subclass of
UIViewController, and any view controller can be presented modally by
your application. You use them when you want to show that there is a spe-
cial relationship between the previous screen and the new one.
Modal controllers are used in two ways:
To get information needed by the presenting controller from the user
To temporarily display some content or force a change to what the user
is currently doing (like the Info button you often see)
Modal view controllers are about redirecting the user’s workflow temporar-
ily in order to gather or display some information. After you have the infor-
mation you need (or after you’ve presented the user with the appropriate
information), you dismiss the modal view controller to return the applica-
tion’s previous state.
41_542934-bk07ch01.indd 75641_542934-bk07ch01.indd 756 3/23/10 11:01 PM3/23/10 11:01 PM