繁体   English   中英

iOS 8:ABPeoplePickerNavigationController在实现人员选择器委托方法时被解雇

[英]ios 8 : ABPeoplePickerNavigationController dismiss on implementing people picker delegate methods

这是从ios 8中的通讯录访问联系人详细信息时发现的奇怪行为。我的情况很简单

  1. 显示联系人表
  2. 选择将调用didSelectPerson方法的行
  3. 在didSelectPerson方法中
  4. 推送SecondViewController

     - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person; { SecondViewController *detailVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; [detailVC.view setBackgroundColor: [UIColor redColor]]; // [peoplePicker.navigationController pushViewController:detailVC animated:YES]; [peoplePicker pushViewController:detailVC animated:YES]; } 

但是发生的是ABPeoplePickerNavigationController关闭。 请对此给予启发。

我不知道在“ didSelectPerson ”方法的幕后发生了什么,今天我也面临着同样的问题。 我找到了解决此问题的简单解决方案,我重写了“ ABPeoplePickerNavigationController ”的“ -(void)dismissViewControllerAnimated:(BOOL)flag补全:(void(^)(void))completion ”方法。 然后像下面这样实现它

    bool dismissedEnabled;
   -(void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
   {
     if (dismissedEnabled) {
       [super dismissViewControllerAnimated:flag completion:completion];
     }
   }

然后在“ didSelectPerson ”里面,我做了以下

   viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:[NSBundle mainBundle]];

    dismissedEnabled = false;
    [self presentViewController:viewController animated:YES completion:nil];

这对我有用,希望你们也克服它:)

例如,如果您选择一个电子邮件地址的联系人,它将自动关闭。 如果联系人有多个电子邮件,则必须指定一个谓词,该谓词将强制ABPeoplePickerNavigationController将ABPersonViewController推入堆栈。

if ([picker respondsToSelector:@selector(setPredicateForSelectionOfPerson:)])
    {
        // The people picker will select a person that has exactly one email address and call peoplePickerNavigationController:didSelectPerson:,
        // otherwise the people picker will present an ABPersonViewController for the user to pick one of the email addresses.
        picker.predicateForSelectionOfPerson = [NSPredicate predicateWithFormat:@"emailAddresses.@count = 1"];
    }

我相信iOS 8中的默认行为是,在调用didSelectPerson时,会自动关闭ABPeoplePickerNavigationController

未显示SecondViewController的原因(我推断这是问题症状),是因为您正在尝试在SecondViewController ABPeoplePickerNavigationController同时推动SecondViewController 这种重叠的动画是iOS核心视图管理/动画系统试图避免的问题。

发生这种情况时,您可能会在控制台中收到警告。

@Ratul的解决方案之所以有效,是因为它规避了这种默认行为。

在我的场景中,我的代码在从didSelectPerson内部呈现UIAlertController之前睡了一秒钟。 这是一个依赖于ABPeoplePickerNavigationController解雇动画的过程,耗时不到一秒钟。 对我而言,如果未显示此警报,则没人会注意到这是一个问题。

如果您想要更强大的功能,则可能需要重写viewDidAppear来处理这种特殊情况(使用呈现的视图控制器中的标志)。 但这也有些笨拙。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM