Datasheet

Book VII
Chapter 1
A User Interface
for Adding Hotels
and Using the
Address Book
781
Interfacing with the Address Book Application
city.text = (NSString*)CFDictionaryGetValue
(dictionary, kABPersonAddressCityKey);
state.text = (NSString*)CFDictionaryGetValue
(dictionary, kABPersonAddressStateKey);
zip.text = (NSString*)CFDictionaryGetValue
(dictionary, kABPersonAddressZIPKey);
CFRelease(dictionary);
}
You could, however, iterate through and find the one with the label you’re
interested in, such as home or work.
for(int i=0;
i < ABMultiValueGetCount(multiValueRef); i++) {
if ([(NSString*)
ABMultiValueCopyLabelAtIndex(multiValueRef, i)
isEqualToString:(NSString*)kABHomeLabel])
...
You could also let the user select the right address (or name field for that
matter) by returning YES instead of NO in the peoplePickerNavigation
Controller:shouldContinueAfterSelectingPerson: method and
implementing the logic to copy the values in peoplePickershould
ContinueAfterSelectingPerson:.
You also can allow the user to access groups as well, but you can explore
that one on your own.
Add the code in Listing 1-21 to AddHotelController.m to add the
required delegate method.
Listing 1-21: (ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier{
return NO;
}
This method won’t be invoked because you returned NO in peoplePicker
NavigationController:shouldContinueAfterSelectingPerson:,
but you still need it there because it is required by the protocol.
Finally, if the user changes his or her mind and wants to cancel the Address
Book lookup, add the code in Listing 1-22.
41_542934-bk07ch01.indd 78141_542934-bk07ch01.indd 781 3/23/10 11:01 PM3/23/10 11:01 PM