popViewController:动画:在iOS 9中不起作用

问题描述 投票:2回答:4

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

在一种情况下,我需要在主流中弹出另一个之前以模态方式呈现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.

到目前为止,这从来都不是问题,特别是因为在完成块中调用了popViewController方法。

这可能是个错误吗?

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

ios objective-c uiviewcontroller uinavigationcontroller ios9
4个回答
7
投票

dispatch_async块中包装popViewController调用有效。

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

0
投票

它在标准UINavigationController中对我有用,即使你得到一个“不平衡调用开始/结束外观转换”警告。以下代码替换popViewControllerAnimated:摆脱了这个警告。

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

所以我猜这个问题就在你的子类中。你会覆盖presentViewController:animated:completion:popViewControllerAnimated:吗?


0
投票

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

controller.dismissViewControllerAnimated(true, completion: nil)

其中“controller”是呈现VC实例。


0
投票

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

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.