ABPeoplePickerNavigationController委托不起作用

时间:2013-12-07 03:40:16

标签: ios delegates abpeoplepickerview

我的目标是允许用户从联系人导入联系人详细信息(电话,姓名和电子邮件)。当我设置ABPeoplePickerNavigationController并将委托设置为self时,不会调用委托方法。正在显示人员选择器视图这是我的代码:

-(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框架的一部分。它也不在文档中。

2 个答案:

答案 0 :(得分:4)

您正在设置delegate,它描述了应该处理UINavigationController的委托方法的对象。

更改

newNavController.delegate = self;

newNavController.peoplePickerDelegate = self;

(如Class Reference中所述,ABPeoplePickerNavigationController是UINavigationController的子类。对于具有多个委托的对象,即使在同一个类中也是如此。)

答案 1 :(得分:0)

使用这个 - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person