我的目标是允许用户从联系人中导入联系人详细信息(电话、姓名和电子邮件)。当我设置 ABPeoplePickerNavigationController 并将委托(delegate)设置为 self 时,不会调用委托(delegate)方法。正在显示人员选择器 View 这是我的代码:
-(IBAction)importFromContacts:(id)sender
{
ABPeoplePickerNavigationController *newNavController = [[ABPeoplePickerNavigationController alloc] init];
newNavController.delegate = self;
[self presentViewController:newNavController animated:YES completion:nil];
}
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
NSLog(@"cancel");
[self dismissViewControllerAnimated:YES completion:nil];
}
我错过了什么?我还想补充一点,类 ABPeoplePicker 似乎不再是 UIAddressBook 框架的一部分。它也不在文档中。
最佳答案
您正在设置 delegate
,它描述了应该处理 UINavigationController 的委托(delegate)方法的对象。
改变
newNavController.delegate = self;
到
newNavController.peoplePickerDelegate = self;
(如 Class Reference 中所述,ABPeoplePickerNavigationController 是 UINavigationController 的子类。即使在同一类中,一个对象拥有多个委托(delegate)也很正常。)
关于ios - ABPeoplePickerNavigationController 委托(delegate)不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20437276/