popViewController:已设置动画:在iOS 9中不工作

popViewController:已设置动画:在iOS 9中不工作,ios,objective-c,uiviewcontroller,uinavigationcontroller,ios9,Ios,Objective C,Uiviewcontroller,Uinavigationcontroller,Ios9,我正在使用一个子类UINavigationController来管理我应用程序中的所有ViewController。它在主流程中推送和弹出ViewController,并以模态方式显示和解除那些任意需要的ViewController 在一种情况下,在主流程中弹出另一个视图控制器之前,我需要以模式显示一个viewController,如下所示: //Called in custom UINavigationController subclass [self presentViewControlle

我正在使用一个子类UINavigationController来管理我应用程序中的所有ViewController。它在主流程中推送和弹出ViewController,并以模态方式显示和解除那些任意需要的ViewController

在一种情况下,在主流程中弹出另一个视图控制器之前,我需要以模式显示一个viewController,如下所示:

//Called in custom UINavigationController subclass
[self presentViewController:searchVC animated:YES completion:^{
    [self popViewControllerAnimated:NO]; 
}];
上面的代码在iOS 8之前都可以正常工作,但在iOS 9中不起作用。当显示的vc被解除时,与以前相同的viewController仍然存在

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

popViewControllerAnimated: called on <CustomNavigationController 0x7d846600> while an existing transition or presentation is occurring; the navigation stack will not be updated.
popViewControllerAnimated:在现有转换或演示发生时调用;导航堆栈将不会更新。
到目前为止,这从来不是一个问题,特别是因为在完成块中调用了popViewController方法

这可能是一只虫子吗


欢迎提供任何解决方案/建议/解决方案。

在标准的
UINavigationController
中,它确实适用于我,即使您收到“开始/结束外观转换的调用不平衡”警告。以下代码替换了
popViewControllerAnimated:
删除了该警告

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

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

将popViewController调用包装在
调度\u async
块中

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

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


其中“controller”是当前的VC实例。

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

否,我不会覆盖这些方法。我可以通过在dispatch\u异步块中调用popViewController来解决这个问题。然而,带有“开始/结束外观转换的不平衡调用”的消息现在被记录下来。我在回答中发布的代码应该可以解决这个问题。它也可能不需要
dispatch\u async
包装器。这样做似乎非常不安全。
controller.dismissViewControllerAnimated(true, completion: nil)