iosabaddressbookabpeoplepickerview

Custom text over ABPeoplePickerNavigationController "All Contacts" header


In Apple Calendar app, if you inviting people to event you will see specific text under header:

Apple Calendar

In my app I'm using people picker too. I would like to add a custom hint for a user over All Contacts header.

My app

IBAction for a button:

- (IBAction)showPicker:(UIBarButtonItem *)sender {
self.addressBookController = [[ABPeoplePickerNavigationController alloc] init];
[self.addressBookController setPeoplePickerDelegate:self];
self.addressBookController.displayedProperties = [NSArray arrayWithObjects:
                                                  [NSNumber numberWithInt:kABPersonPhoneProperty],
                                                  nil];
[self presentViewController:self.addressBookController animated:YES completion:nil];

}

All delegate methods:

#pragma mark Address Book Delegate

-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
[self.addressBookController dismissViewControllerAnimated:YES completion:nil];
}


-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{
return YES;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {

ABMultiValueRef phonesRef = ABRecordCopyValue(person, property);
CFStringRef currentPhoneValue = ABMultiValueCopyValueAtIndex(phonesRef, identifier);

// Some custom code working with a phone number

return NO;
}

Solution

  • I don't think there is a way to customize the ABPeoplePickerNavigationController anyhow. You can create a UIViewController with a UILabel (with your hint for users) and a container view; then embed ABPeoplePickerNavigationController into the container view. This can be easily achieved via Interface Builder and also can be done programmatically, see the Implementing a Container View Controller section in UIViewController's Class Reference Overview.

    Update

    Unfortunately it seems that ABPeoplePickerNavigationController can't be added directly to the Storyboard; please refer to this answer to see a workaround.