Datasheet

760
Adding Some Code to Actually Add Some Functionality
Because you can never be too careful, add the code in bold in Listing 1-7 to
initWithTrip: in HotelController.m to initialize the amEditing state.
Listing 1-7: Initializing the State
- (id) initWithTrip: (Trip*) aTrip{
if (self =
[super initWithNibName:@”HotelController” bundle:nil]) {
trip = aTrip;
[trip retain];
amEditing = NO;
}
return self;
}
Next, set the state to amEditing in insertNewObject in
HotelController.m by adding the bolded code in Listing 1-8. That way,
when the AddHotelController is presented, you’ll do nothing in view-
DidDisappear:.
Listing 1-8: Setting the State to amEditing
- (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;
41_542934-bk07ch01.indd 76041_542934-bk07ch01.indd 760 3/23/10 11:01 PM3/23/10 11:01 PM