繁体   English   中英

iOS 8-ABPeoplePickerNavigationController-取消委托方法有效,其他方法不起作用

[英]IOS 8 - ABPeoplePickerNavigationController - Cancel delegate method works, others do not

我在IOS 8人员选择器委托代码中遇到了一个奇怪的问题。 只有

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController    *)peoplePicker;
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}

方法被调用。 我已经审查了其他问题,并通过调用旧的IOS 7方法对选择联系人的IOS 8委托方法进行了重要更改。

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:   (ABMultiValueIdentifier)identifier {
    [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person property:property identifier:identifier];
}

但它从未被调用。

我在调用viewcontroller didLoad中设置委托,

而且它在ios 7中完美运行。这是一个故事板应用程序。

我在这里的评论中看到了相同的问题: ABPeoplePickerNavigationController是否随iOS8更改?

但从未找到答案。 显然我的某个地方有一个错误,但我找不到它。

更新:根据要求,这是我设置委托的方式:

self.picker = [[ABPeoplePickerNavigationController alloc] init];
self.picker.peoplePickerDelegate = self;

并且,在@interface中:

@interface TreatmentsAddEntryTVC :    UITableViewController<UITextViewDelegate,ABPeoplePickerNavigationControllerDelegate>

尝试改用此委托方法,看看是否成功:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person;
{
   // yes the below line is deprecated as of iOS 8
   [self peoplePickerNavigationController:peoplePicker shouldContinueAfterSelectingPerson:person];
}

我讨厌回答我自己的问题,尤其是当答案没有任何意义,只是动容的时候:

self.picker = [[ABPeoplePickerNavigationController alloc] init];
self.picker.peoplePickerDelegate = self;

从didLoad到我实际要显示选择器的方法,可以解决此问题。 我在SO上至少看到了另一个问题,该行为在何处得到记录和讨论:

无法在iOS 8上选择联系人

对于使用iOS 8.1的项目,我替换了此方法

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{ 
}

有了这个

-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{
}

当我选择一个联系人时,新方法就成功了。

暂无
暂无

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

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