我有一个新项目,我想在触摸按钮时显示人员选择器。
所以我有一个带有标识符UIButton
的泛型。我将此 ViewController 的类设置为.UIViewController
showContacts
ABPeoplePickerNavigationController
现在在我的根 ViewController 中,我有这段代码来初始化我的选择器:
#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]];
}
}
尽管我已将测试联系人添加到我的模拟器通讯录中,但结果如下所示:
没有选择器 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];
}
结果:
选择器 http://i.minus.com/jeEVeIBmfIYdR.png
我不清楚为什么人员选择器不显示。