如何让peoplePickerNavigationController自动解除

时间:2014-09-21 01:36:59

标签: ios ipad ios8 peoplepicker

在iOS 8中,不推荐使用以下内容:

  

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

现在我们应该使用:

  

- (无效)peoplePickerNavigationController:didSelectPerson:

但是这个方法会在第一次选择之后自动解除人员选择器,旧版本没有。我有一个例程,需要记录用户逐个选择的每个名称。我可以在每次选择后重新显示人员选择器,但它会以第一个名称重新开始联系人列表。

我希望我能正确解释这一点。任何人都知道如何在iOS 8中保持peoplepickernavigationcontroller不会像在ios7中那样自动解除?

2 个答案:

答案 0 :(得分:2)

在ABPeoplePickerNavigationController的文档中,查看predicateForSelectionOfPerson的注释。

// Optionally determines if a selected person should be returned to the app (predicate evaluates to TRUE),
// or if the selected person should be displayed (predicate evaluates to FALSE).
// If not set and -peoplePickerNavigationController:didSelectPerson: is implemented the selected person is returned to the app,
// or if not set and -peoplePickerNavigationController:didSelectPerson:identifier: is implemented the selected person is displayed.
//
@property(nonatomic,copy) NSPredicate *predicateForSelectionOfPerson NS_AVAILABLE_IOS(8_0);

因此,如果要显示所选人员,则需要设置FALSE谓词。

    if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
{
    picker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:NO];
}

答案 1 :(得分:1)

我找到了一个解决方案,在选择房产后重新展示人员选择器。

实现委托方法,该方法处理一个人选择联系人属性的时间(仅由iOS 8调用):对我而言,诀窍是解除然后选择器,然后立即在完成委托中调用我的“show picker”方法(是的,代表中的代表)。

// Dismisses the people picker and shows the application when users tap Cancel.
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {


    [self.picker dismissViewControllerAnimated:NO completion:^{
        NSLog(@"just dismissed the picker");
        [self showPeoplePickerController];
    }];
}

如果您希望它显示在最后一次停止的位置,请务必初始化人员选择器。希望这有帮助

这是我的showPeoplePickerController方法

#pragma mark Show all contacts
// Called when users tap "Display Picker" in the application. Displays a list of contacts and allows users to select a contact from that list.
-(void)showPeoplePickerController

{
        picker.peoplePickerDelegate = self;
        picker.delegate = self;
        picker.visibleViewController.searchDisplayController.searchBar.delegate = self;

        [self presentViewController:picker animated:NO completion:nil];  
}

首先初始化选择器。请注意,首先是联系人访问需要授权方法调用

picker = [[ABPeoplePickerNavigationController alloc] init];
//have self prompt first, then based off answer prompt them with internal address book stuff or now
if(ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
{
    // show picker UI if the user has granted access to their Contacts
    [self showPeoplePickerController];
}

注意:

  • 我以前在加载视图时启动了人员选择器。一次。
  • 在呈现和解除控制器时将“动画”选项设置为NO有助于使转换更顺畅。