简体   繁体   English

在iOS8上将ABPersonViewController推送到ABPeoplePickerNavigationController

[英]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.

相关问题 ABPeoplePickerNavigationController随iOS8变化? - ABPeoplePickerNavigationController changes with iOS8? 带有UITabBarController的ABPeoplePickerNavigationController在iOS8中无法正确显示 - ABPeoplePickerNavigationController with UITabBarController is not showing correctly in iOS8 具有可编辑的ABPersonViewController的ABPeoplePickerNavigationController - ABPeoplePickerNavigationController with editable ABPersonViewController 推送 ABPersonViewController 时,应用程序在 iOS 13 中崩溃 - App crashes in iOS 13 when pushing ABPersonViewController iOS ABPersonViewController - iOS ABPersonViewController 如何正确使用ABPersonViewController与ABPeoplePickerNavigationController查看联系信息? - How to correctly use ABPersonViewController with ABPeoplePickerNavigationController to view Contact information? iOS 8 ABPeoplePickerNavigationController多项选择 - iOS 8 ABPeoplePickerNavigationController Multiple Selection iOS8:在prepareForSegue中将View Controller推入另一个闪烁 - iOS8: Pushing View Controller in prepareForSegue for another flashes it 在iOS 7中的ABPeoplePickerNavigationController中添加barButtonItems - Add barButtonItems in ABPeoplePickerNavigationController in ios 7 iOS7 - ABPersonViewController,编辑模式 - iOS7 - ABPersonViewController, editing mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM