Datasheet
782
Interfacing with the Address Book Application
Listing 1-22: Canceling the addition
- (void)peoplePickerNavigationControllerDidCancel:
(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
All you really do here is dismiss the controller.
To finish up, you also need to add some imports to
AddHotelController.h.
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
Next, you need to add the AddressBook and AddressBookUI Frameworks.
1. Click the disclosure triangle next to Targets in the Groups & Files list
and then right-click RoadTrip.
Be sure to do this using the Targets folder, or Step 3 won’t work!
2. From the menu that appears, select Add and then select Existing
Frameworks.
3. Select AddressBook.framework and the AddressBookUI.frame-
work in the window that appears and then drag them into the
Frameworks folder.
Adding a hotel to your Address Book
Adding a new contact to the Address Book is similar to accessing one.
You’d start by making the AddHotelController a
ABNewPersonViewControllerDelegate. You’ll need to add the following
to AddHotelController.h.
@interface AddHotelController : UIViewController
<UITextFieldDelegate,
ABPeoplePickerNavigationControllerDelegate,
ABNewPersonViewControllerDelegate> {
In this case, there is only one delegate method you’ll need to implement —
the newPersonViewController:didCompleteWithNewPerson:
method, which is invoked when the user taps Save or Cancel. By the way,
if the user tapped Save, by the time you receive the message, the current
Address Book has been saved to the Address Book database.
At that point, it’s your job to dismiss the AbNewPersonViewController.
Add the code in Listing 1-23 to AddHotelController.m to do just that.
41_542934-bk07ch01.indd 78241_542934-bk07ch01.indd 782 3/23/10 11:01 PM3/23/10 11:01 PM