人员ViewController在选择人员后消失

时间:2014-10-04 18:24:58

标签: ios objective-c abpeoplepickerview

我对ABPersonViewController有疑问。我使用ABPeoplePickerNavigationControllerDelegate来显示人员选择器(联系人列表)。我想在选择一个人时显示一个ABPersonViewController。问题是ABPersonViewController在选择此人后会消失。详细说明 - >我选择一个人 - >出现ABPersonViewController(具有正确的属性) - > ABPersonViewController立即消失,完整的人物也随之消失。我认为问题是我推开了PeoplePicker。

我在教程中阅读了很多内容,但我没理解。我目前正在为IOS 8开发。

大多数教程都使用不同的peoplepicker方法调用ABPersonViewController,但是如果我用另一个委托方法调用它,它就不起作用。

这是我的代码:

@interface ViewController : UIViewController<ABPeoplePickerNavigationControllerDelegate, ABPersonViewControllerDelegate>

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

    ABPersonViewController *picker = [[ABPersonViewController alloc] init];
    picker.personViewDelegate = self;
    picker.displayedPerson = person;
    picker.displayedProperties = peoplePicker.displayedProperties;
    picker.allowsActions = YES;
    [peoplePicker pushViewController:picker animated:YES];
    return NO;
}

提前谢谢。

问候

1 个答案:

答案 0 :(得分:0)

在iOS8中,初始化ABPeoplePickerNavigationController时需要添加如下代码,否则在选择联系人后,peoplePickerNavigationController将立即解除。

if(IOS8_OR_LATER){
    peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false];
}

此外,对于iOS 8,请使用

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier 

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

而不是

  

shouldContinueAfterSelectingPerson

因为此方法已在iOS8中弃用