7

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

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

现在我们应该使用:

-(无效)peoplePickerNavigationController:didSelectPerson:

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

我希望我正确地解释了这一点。任何人都知道如何防止 peoplepickernavigationcontroller 在 iOS 8 中像以前在 ios7 中那样自动关闭?

4

2 回答 2

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];
}
于 2015-01-19T09:01:40.513 回答
1

我找到了在选择属性后重新显示人员选择器的解决方案。

实现当一个人选择联系人属性时处理的委托方法(仅由 iOS 8 调用):对我来说,诀窍是先关闭选择器,然后立即在完成委托中调用我的“显示选择器”方法(是的,内部的委托代表)。

// 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 有助于使过渡更平滑。
于 2014-10-05T05:44:59.530 回答