adding all person in form of array in ABRecordRef
how can i add the people from the contacts to 'people'- array then to abrecordref.??? Actually i want all the contacts in tableview and can able to edit individual record. here is my code:
-(void)showPersonViewController
{
// Fetch the address book
ABAddressBookRef addressBook = ABAddressBookCreate();
// Search for the person named "rubal" in the address book
NSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("naina"));
// Display "KETAN" information if found in the address book
if ((people != nil) && [people count])
{
ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];
ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];
picker.personViewDelegate = self;
picker.displayedPerson = person;
// Allow users to edit the person’s information
picker.allowsEditing = YES;
[self.navigationController pushViewController:picker animated:YES];
}
else
{
// Show an alert if "KETAN" is not in Contacts
UIAlertView *开发者_运维百科alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Could not find naina in the Contacts application"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
[alert release];
}
[people release];
CFRelease(addressBook);
}
instead of only 'naina' i want all record in table view and edit individually
Look at ABPerson Class Reference. There is a list of other copy functions, including the one you seek, ABAddressBookCopyArrayOfAllPeople(ABAddressBookRef ab)
comment out your function and add this one and see if it works
-(BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
[peoplePicker dismissModalViewControllerAnimated:NO];
ABPersonViewController *picker = [[ABPersonViewController alloc] init];
picker.personViewDelegate = self;
picker.displayedPerson = person;
// Allow users to edit the person’s information
picker.allowsEditing = YES;
[picker setValue:[NSNumber numberWithBool:YES] forKey:@"allowsDeletion"];
[self.navigationController pushViewController:picker animated:YES];
return YES;
}
精彩评论