Open Contact List at Specific Contact
I have an iPhone app that uses a ABPeoplePickerNavigationController
to pick out a contact. First time you select a contact, the contact list obviously starts at the top, under the letter 'A'. However, say you selected a contact under 'M'; if you then later want to change which contact is selected, I want to initialise the contact list so that it's already scrolled to the 'M' section.
Here's the code I use to open the contact list:
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
I can't find any information in the reference guide on how to configure the scroll offset where the controller开发者_开发百科 opens.
This functionality is unavailable in ABPeoplePickerNavigationController
. However you can implement a custom UITableViewController
which does that using the AddressBook
framework.
Try to use the [ABAddressBook]
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for( int i = 0 ; i < nPeople ; i++ )
{
ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i );
NSString* name = [(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) autorelease];
}
精彩评论