Ho un nuovo progetto in cui voglio visualizzare un People Picker, quando viene toccato un pulsante.Mostra ABPeoplePickerNavigationController utilizzando storyboard seguito
Quindi ho un UIButton
che passa a un UIViewController
generico con l'identificatore showContacts
. Ho impostato la classe di questo ViewController su ABPeoplePickerNavigationController
.
Ora nel mio ViewController radice ho questo codice per inizializzare il mio 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]];
}
}
Anche se ho aggiunto contatti di test al mio Simulator Rubrica i risultati si presenta così:
no picker http://i.minus.com/jbwUQyLr36ChHo.png
Con il seguente codice, che è molto simile a quello che faccio nel metodo prepareForSegue:
, riesco a mostrare un selettore tramite un 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];
}
Il risultato:
picker http://i.minus.com/jeEVeIBmfIYdR.png
Non è chiaro perché il selettore gente non mostra.