Question

I have a new project where I want to display a People Picker, when a button is touched.

So I have a UIButton that segues to a generic UIViewController with the identifier showContacts. I set the class of this ViewController to ABPeoplePickerNavigationController.

Now in my root ViewController I have this code to initialize my picker:

#pragma mark - Segues

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if([segue.identifier isEqualToString:@"showContacts"]){
        ABPeoplePickerNavigationController *ppnc = segue.destinationViewController;
        ppnc.peoplePickerDelegate = self;
        ppnc.addressBook = ABAddressBookCreate(); 
        ppnc.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
    }
}

Although I have added test contacts to my Simulator Address book the results looks like this:

no picker http://i.minus.com/jbwUQyLr36ChHo.png

With the following code, which is very similar to what I do in the prepareForSegue: method, I manage to show a picker via an IBAction:

- (IBAction)showPicker:(id)sender {

    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    picker.peoplePickerDelegate = self;
    NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], 
                               [NSNumber numberWithInt:kABPersonEmailProperty],
                               [NSNumber numberWithInt:kABPersonBirthdayProperty], nil];
    picker.displayedProperties = displayedItems;
    // Show the picker 
    [self presentModalViewController:picker animated:YES];
}

The result:

picker http://i.minus.com/jeEVeIBmfIYdR.png

It is not clear to me why the People picker does not show.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top