我有一個新的項目,我想要顯示人員選取器,當一個按鈕被觸摸。顯示ABPeoplePickerNavigationController使用故事板segue
因此,我有一個UIButton
,後續通用UIViewController
與標識showContacts
。我將這個ViewController的類設置爲ABPeoplePickerNavigationController
。
現在在我的根視圖控制器我有這樣的代碼來初始化我選擇器:
#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]];
}
}
雖然我已經加入測試接觸到我的模擬器地址簿的結果是這樣的:
no picker http://i.minus.com/jbwUQyLr36ChHo.png
下面的代碼與我在prepareForSegue:
方法中做的非常相似,我設法通過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];
}
結果:
picker http://i.minus.com/jeEVeIBmfIYdR.png
爲什麼人員選取器不顯示這是我不清楚。