Mam nowy projekt, w którym chcę wyświetlić selektor osób po dotknięciu przycisku.Wyświetl ABPeoplePickerNavigationController przy użyciu serii scencase
Więc mam UIButton
, który łączy się z generycznym UIViewController
z identyfikatorem showContacts
. Ustawiłem klasę ViewController na ABPeoplePickerNavigationController
.
Teraz moim głównym ViewController Mam ten kod, aby zainicjować moje próbnika:
#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]];
}
}
Chociaż Dodałem kontakty testowe do mojego Simulator książki adresowej wyników wygląda tak:
no picker http://i.minus.com/jbwUQyLr36ChHo.png
Poniższy kod, który jest bardzo podobny do tego, co robię w metodzie prepareForSegue:
, udaje mi się pokazać selektor za pomocą 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];
}
Rezultat:
picker http://i.minus.com/jeEVeIBmfIYdR.png
To nie jest dla mnie jasne, dlaczego ludzie zbieracz nie pokazuje.