popViewController:animated:在 iOS 9 中不工作

popViewController:animated: not working in iOS 9

我正在使用子类 UINavigationController,它管理我应用程序中的所有 viewController。它在主流中推送和弹出 viewControllers,并以模态方式呈现和关闭那些任意需要的 viewControllers。

在一种情况下,我需要在主流程中弹出另一个之前先模态呈现一个 viewController,如下所示:

//Called in custom UINavigationController subclass
[self presentViewController:searchVC animated:YES completion:^{
    [self popViewControllerAnimated:NO]; 
}];

上面的代码在 iOS 8 之前可以正常工作,在 iOS 9 中不起作用。当出现 [=31] 时,与以前相同的 viewController 仍然存在=] 被驳回。

此外,这正在控制台中记录:

popViewControllerAnimated: called on <CustomNavigationController 0x7d846600> while an existing transition or presentation is occurring; the navigation stack will not be updated.

直到现在这都不是问题,特别是因为在完成块中调用了 popViewController 方法。

这可能是一个错误吗?

欢迎任何solution/suggestion/workaround。

它在标准 UINavigationController 中对我有用,即使您收到 "Unbalanced calls to begin/end appearance transitions" 警告。以下替换 popViewControllerAnimated: 的代码消除了该警告。

NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
[viewControllers removeLastObject];
self.navigationController.viewControllers = [viewControllers copy];

所以我猜问题出在你的子类中。您是否覆盖 presentViewController:animated:completion:popViewControllerAnimated:

dispatch_async 块中包装 popViewController 调用有效。

[self presentViewController:searchVC animated:YES completion:^{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self popViewControllerAnimated:YES];
    }); 
}];

是的,我在 iOS 9 中也注意到了这个问题。 我将代码更改为 (Swift):

controller.dismissViewControllerAnimated(true, completion: nil)

其中 "controller" 是呈现的 VC 实例。

如果您使用的是拆分视图控制器,请尝试将其删除。