简体   繁体   English

ABPeoplePickerNavigationController委托不起作用

[英]ABPeoplePickerNavigationController Delegate Not Working

My goal is to allow the user to import contact details (phone, name and email) from contacts. 我的目标是允许用户从联系人中导入联系人详细信息(电话,姓名和电子邮件)。 When I set up an ABPeoplePickerNavigationController and set the delegate to self, the delegate methods are not being called. 当我设置ABPeoplePickerNavigationController并将委托设置为self时,不会调用委托方法。 The people picker view is being displayed Here is my code: 正在显示人员选择器视图这是我的代码:

-(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];
}

What am I missing? 我想念什么? I would also like to add that the class ABPeoplePicker does not seem to be part of the UIAddressBook framework anymore. 我还要补充一点,该类ABPeoplePicker似乎不再是UIAddressBook框架的一部分。 It is not in the docs either. 它也不在文档中。

You're setting delegate , which describes the object that should handle UINavigationController's delegate methods. 您正在设置delegate ,该delegate描述了应该处理UINavigationController的委托方法的对象。

Change 更改

newNavController.delegate = self;

to

newNavController.peoplePickerDelegate = self;

(As described in the Class Reference , ABPeoplePickerNavigationController is a subclass of UINavigationController. It's not out of the ordinary for an object to have multiple delegates, even within the same class.) (如类参考中所述,ABPeoplePickerNavigationController是UINavigationController的子类。即使在同一个类中,对象具有多个委托也并非异常。)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM