简体   繁体   English

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

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

I've encountered a strange problem in my IOS 8 people picker delegate code. 我在IOS 8人员选择器委托代码中遇到了一个奇怪的问题。 Only the 只有

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

method is being called. 方法被调用。 I have reviewed other questions and have made the important IOS 8 delegate method changes for selecting a contact by calling the old IOS 7 method 我已经审查了其他问题,并通过调用旧的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];
}

but it is never called. 但它从未被调用。

I am setting the delegate in the calling viewcontroller didLoad, 我在调用viewcontroller didLoad中设置委托,

and it works perfectly in ios 7. This is a storyboard application. 而且它在ios 7中完美运行。这是一个故事板应用程序。

I saw the same question asked in a comment here: ABPeoplePickerNavigationController changes with iOS8? 我在这里的评论中看到了相同的问题: ABPeoplePickerNavigationController是否随iOS8更改?

but never found an answer. 但从未找到答案。 Obviously a mistake somewhere on my part, but I can't find it. 显然我的某个地方有一个错误,但我找不到它。

UPDATE: As requested, here is how I set the delegate: 更新:根据要求,这是我设置委托的方式:

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

And, in @interface: 并且,在@interface中:

@interface TreatmentsAddEntryTVC :    UITableViewController<UITextViewDelegate,ABPeoplePickerNavigationControllerDelegate>

Try using this delegate method instead and see if it hits: 尝试改用此委托方法,看看是否成功:

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

I hate to answer my own question, especially when the answer makes no sense, but moving: 我讨厌回答我自己的问题,尤其是当答案没有任何意义,只是动容的时候:

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

from didLoad to the method where I actually want to display the picker fixed the problem. 从didLoad到我实际要显示选择器的方法,可以解决此问题。 I have seen at least one other question on SO where this behavior was noted and discussed: 我在SO上至少看到了另一个问题,该行为在何处得到记录和讨论:

Cannot select contact on iOS 8 无法在iOS 8上选择联系人

For a project with iOS 8.1, I replaced this method 对于使用iOS 8.1的项目,我替换了此方法

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

with this 有了这个

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

And new method did hit when I selected a contact. 当我选择一个联系人时,新方法就成功了。

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

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