我找到了在选择属性后重新显示人员选择器的解决方案。
实现当一个人选择联系人属性时处理的委托方法(仅由 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 有助于使过渡更平滑。