I've encountered a strange problem in my IOS 8 people picker delegate code. 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
- (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,
and it works perfectly in ios 7. This is a storyboard application.
I saw the same question asked in a comment here: ABPeoplePickerNavigationController changes with 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 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. I have seen at least one other question on SO where this behavior was noted and discussed:
For a project with iOS 8.1, I replaced this method
-(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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.