Datasheet
Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
761
Entering and Saving the Hotel Information
//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;
}
You’ll set amEditing back to NO when you return for the entering data in
the AddHotelController, but you’re not there yet.
Continue on building the AddHotelController.
Entering and Saving the Hotel Information
I’m going to start you off with some simple stuff.
Dismissing the keyboard
To dismiss the keyboard, you need to add another method to the
AddHotelController — textFieldShouldReturn:. With that method,
you have to send a message to the text field to resignFirstResponder.
When the text field receives that message, it lowers the keyboard. (I cover
lowering keyboards, as well as how to scroll the view so that a text field
isn’t covered, in exquisite detail in my iPhone Application Development For
Dummies; if you’re dying to find out more about lowering keyboards and
keeping fields uncovered, you should look at that book.)
Enter the code in Listing 1-9 to AddHotelController.
41_542934-bk07ch01.indd 76141_542934-bk07ch01.indd 761 3/23/10 11:01 PM3/23/10 11:01 PM