Datasheet

Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
773
Interfacing with the Address Book Application
Interfacing with the Address Book Application
I started this chapter off by musing about how nice it would be to be able to
add an existing contact in your Address Book to your Hotels list. Actually,
doing that is easy, but in doing so you’re sure to come across some concepts
and record types that may seem a little alien. But no worries. Soon you’ll be
making your way through them like an old hand.
As you recall, you connected the Get from Contacts button to an IBAction
method back in the “Setting up the controller” section, earlier in the chap-
ter. Now, you have a chance to implement that method — and get rid
of one pesky compiler warning to boot. Add the code in Listing 1-18 to
AddHotelController.m.
Listing 1-18: getFromContacts:
#pragma mark -
#pragma mark Get from contacts
- (IBAction) getFromContacts:(id)sender {
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
Entering this little bit of code results in displaying the Address Book inter-
face that you see in Figure 1-17.
As you can see, all you really do is present a modal view controller. The one
you’ll be using here is one of the standard system view controllers that are
part of the iPhone OS.
In most ways, presenting these standard view controllers works the same
as for your custom view controllers. However, because your application
doesn’t have access to the views used in these controllers — surprise, sur-
prise — all interactions with the system view controllers must take place
through a delegate object.
To enable that, you’ll find each system view controller defines a correspond-
ing protocol, whose methods you implement in your delegate object. And,
as with your own modal controllers, one of the most important things the
delegate must do is dismiss the presented view controller by calling the
dismissModalViewControllerAnimated: method of the view con-
troller that did the presenting. In this chapter, you’ll be working with the
AddressBook UI controllers, which include
41_542934-bk07ch01.indd 77341_542934-bk07ch01.indd 773 3/23/10 11:01 PM3/23/10 11:01 PM