1

这是在 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 解雇。请赐教。

4

3 回答 3

0

我不知道“ didSelectPerson ”方法背后发生了什么哲学问题,我今天也面临同样的问题。我找到了一个简单的解决方案来克服这个问题,我覆盖了“ ABPeoplePickerNavigationController ”的“ -(void)dismissViewControllerAnimated:(BOOL)flag completion:(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];

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

于 2014-12-08T09:02:24.863 回答
0

例如,如果您选择具有单个电子邮件地址的联系人,它会自动关闭。如果一个联系人有多个电子邮件,您必须指定一个谓词,该谓词将强制 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"];
    }
于 2014-12-08T14:45:01.527 回答
0

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

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

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

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

UIAlertController在我的场景中,我的代码在呈现from inside 之前会休眠一秒钟didSelectPerson。这是一个依赖于ABPeoplePickerNavigationController不到一秒的解雇动画的技巧。对我来说,如果不显示此警报,甚至没有人会注意到这是一个问题。

如果您想要更健壮的东西,您可能需要重写viewDidAppear以处理这种特殊情况(在呈现视图控制器中使用标志)。但这也有点笨拙。

于 2015-03-04T08:12:27.867 回答