Afficher ABPeoplePickerNavigationController à l'aide du séquencement de storyboard

J'ai un nouveau projet où je veux afficher un sélecteur de personnes, quand un button est touché.

J'ai donc un UIButton qui se UIViewController à un UIViewController générique avec l'identifiant showContacts . J'ai mis la class de ce ViewController à ABPeoplePickerNavigationController .

Maintenant, dans mon ViewController racine j'ai ce code pour initialiser mon sélecteur:

 #pragma mark - Segues -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if([segue.identifier isEqualToSsortingng:@"showContacts"]){ ABPeoplePickerNavigationController *ppnc = segue.destinationViewController; ppnc.peoplePickerDelegate = self; ppnc.addressBook = ABAddressBookCreate(); ppnc.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]]; } } 

Bien que j'ai ajouté des contacts de test à mon carnet d'adresses de simulateur, les résultats ressemblent à ceci:

pas de sélecteur http://i.minus.com/jbwUQyLr36ChHo.png

Avec le code suivant, qui est très similaire à ce que je fais dans la méthode prepareForSegue: je parviens à montrer un sélecteur via 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]; } 

Le résultat:

sélecteur http://i.minus.com/jeEVeIBmfIYdR.png

Ce n'est pas clair pour moi pourquoi le sélecteur de personnes ne montre pas.

La réponse de Besi est géniale. Mais c'est less de code de simplement utiliser l'ancienne méthode au lieu d'utiliser un storyboard pour cela:

 - (void)showPeoplePicker:(id)sender { ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init]; picker.peoplePickerDelegate = self; picker.modalPresentationStyle = UIModalPresentationFullScreen; picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentViewController:picker animated:YES completion:^{ // animation to show view controller has completed. }]; } 

Curieusement, ce que j'ai suggéré sur Puis-je utiliser des segments avec des initialiseurs désignés de controllers de vue? résolu le problème pour moi aussi. Donc, la création d'un proxy ViewController pour ABPeoplePickerNavigationController résout le problème, mais n'explique pas pourquoi les ABPeoplePickerNavigationController ne peuvent pas être utilisés dans les storyboards:

C'est le code pour ma class wrapper:

 #import "PeoplePickerViewControllerWrapper.h" @implementation PeoplePickerViewControllerWrapper @synthesize ppvc = _ppvc; // This is the object I'm proxying (The proxyee so to speak) @synthesize delegate = _delegate; - (void)awakeFromNib { self.ppvc = [[ABPeoplePickerNavigationController alloc] init ]; self.ppvc.peoplePickerDelegate = self; self.ppvc.addressBook = ABAddressBookCreate(); self.ppvc.displayedProperties = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]]; } #pragma mark - View lifecycle - (void)loadView { [super loadView]; [self.ppvc loadView]; } - (void)viewDidLoad { [super viewDidLoad]; [self.ppvc viewDidLoad]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.ppvc viewWillAppear:animated]; } -(void)viewDidDisappear:(BOOL)animated{ [super viewDidDisappear:animated]; [self.ppvc viewDidDisappear:animated]; } -(UIView *)view{ return self.ppvc.view; } - (void)viewDidUnload { [super viewDidUnload]; [self.ppvc viewDidUnload]; } 

Comme Matt a noté le bon vieux path est ok. Si vous voulez utiliser le storyboard, vous pouvez append ABPeoplePickerNavigationController dans votre controller de vue personnalisé comme ceci:

 - (void)awakeFromNib { ABPeoplePickerNavigationController * peoplePicker = [[ABPeoplePickerNavigationController alloc] init]; peoplePicker.peoplePickerDelegate = self; // Display only a person's phone and address NSArray * displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonAddressProperty], [NSNumber numberWithInt:kABPersonPhoneProperty], nil]; peoplePicker.displayedProperties = displayedItems; [self.view addSubview:peoplePicker.view]; [self addChildViewController:peoplePicker]; [peoplePicker didMoveToParentViewController:self]; }