Datasheet

Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
767
Entering and Saving the Hotel Information
Listing 1-14: Updating insertNewObject
- (void)insertNewObject {
NSEntityDescription *entity = [[fetchedResultsController
fetchRequest] entity];
hotel = [NSEntityDescription insertNewObjectForEntit
yForName:[entity name] inManagedObjectContext:trip.
managedObjectContext]; //$$
[self setUpUndoManager];
[hotel setValue:@”Hotel California” forKey:@”name”];
[hotel setValue:@”1 Dr. Carlton B. Goodlett Place”
forKey:@”street”];
[hotel setValue:@”San Francisco” forKey:@”city”];
[hotel setValue:@”California” forKey:@”state”];
[hotel setValue:@”94102” forKey:@”zip”];
amEditing = YES;
AddHotelController *addHotelController =
[[AddHotelController alloc] initWithHotel:hotel
trip:trip];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController
:addHotelController];
navigationController.modalTransitionStyle =
UIModalTransitionStyleFlipHorizontal;
addHotelController.delegate = self;
[self presentModalViewController:navigationController
animated:YES];
[navigationController release];
[addHotelController release];
//Annotation *annotation = [NSEntityDescription
insertNewObjectForEntityForName:@”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;
}
41_542934-bk07ch01.indd 76741_542934-bk07ch01.indd 767 3/23/10 11:01 PM3/23/10 11:01 PM