[英]Pushing ABPersonViewController to ABPeoplePickerNavigationController on iOS8
Presenting the people picker 介绍人员选择器
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.allowsActions = YES;
peoplePicker.allowsEditing = NO;
peoplePicker.peoplePickerDelegate = self;
[self presentViewController:peoplePicker animated:YES completion:nil];
Implementing the ABPeoplePickerNavigationControllerDelegate in iOS 7 在iOS 7中实现ABPeoplePickerNavigationControllerDelegate
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.displayedPerson = person;
[peoplePicker pushViewController:personViewController animated:YES];
return NO;
}
So far so good. 到现在为止还挺好。 The person view controller is presented as expected.
人员视图控制器按预期方式提供。 iOS7 method returns a value - one could return NO in order to make sure the people picker remains open.
iOS7方法返回一个值-可以返回NO以确保人员选择器保持打开状态。 In iOS8 the above delegate method was deprecated and new method must be implemented:
在iOS8中,不建议使用上述委托方法,并且必须实现新方法:
- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person {
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.displayedPerson = person;
[peoplePicker pushViewController:personViewController animated:YES];
}
The person view controller is pushed to the people picker but after a fraction of a second the people picker is dismissed (together with the person view controller). 人员视图控制器被推到人员选择器,但是一秒钟之后,人员选择器被关闭(与人员视图控制器一起)。
Is there a way to prevent the people picker from dismissing on iOS8? 有没有一种方法可以防止人员选择器在iOS8上被解雇? Any other suggestions?
还有其他建议吗?
-(void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person
{
[self dismissViewControllerAnimated:NO completion:^{
ABPersonViewController *personController = [[ABPersonViewController alloc] init];
[personController setDisplayedPerson:person];
[personController setPersonViewDelegate:self];
[personController setAllowsEditing:NO];
personController.displayedProperties = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], nil];
[self.navigationController pushViewController:personController animated:YES];
}];
}
如何使用presentViewController
而不是pushViewController
...在Xcode 6中,它说pushViewController已过时,我看到您正在尝试在iOS8中实现它,因此请尝试一下...像这样的一行:
[peoplePicker presentViewController: personViewController animated: YES completion: nil];
In iOS8, you will need to add code as below when you initialise the ABPeoplePickerNavigationController, otherwise the peoplePickerNavigationController will dismiss right away after you select a contact. 在iOS8中,初始化ABPeoplePickerNavigationController时,需要添加以下代码,否则peoplePickerNavigationController将在您选择联系人后立即关闭。
if(IOS8_OR_LATER){
peoplePicker.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false]; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.