无法弹出viewController

时间:2016-02-02 09:18:03

标签: ios objective-c uiviewcontroller uinavigationcontroller catransition

我正在使用此代码来显示UIViewController:

CATransition *transition = [CATransition animation];
transition.duration = 0.f;
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:newVC animated:NO];

并正确显示viewController。然后我正在使用此代码准备动画(用于为pop设置动画):

CATransition *transition = [CATransition animation];
transition.duration = 0.f;
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];

但是,这些行都不会弹出它:

[self.navigationController popViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:NO];

可能是什么问题?记录导航堆栈会显示正确的UIViewControllers

NSLog(@"%@", self.navigationController.viewControllers);

3 个答案:

答案 0 :(得分:2)

这很清楚,

如果您没有推送 yourViewcontroller,则无法弹出yourViewController

如果代码中缺少贝娄线

 [self.navigationController pushViewController:newVC animated:NO];

以下两者都不会执行

[self.navigationController popViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:NO];

答案 1 :(得分:0)

好的,这很令人尴尬。

我正在viewDidAppear:animated:中运行推送呼叫,如果我们已经推送,我忘记执行检查。因此,当我弹出新UIViewController时,viewDidAppear:animated再次重新推送新VC。我还将其设置为animate:NO并删除了自定义转换,导致弹出和重新推送基本上立即发生。

我通过在pop消息上放置一个断点来发现这一点,并注意到模拟器在几分之一秒内显示了根UIViewController

答案 2 :(得分:0)

set your navigationItems left / right / title to nil before

[self.navigationController popViewControllerAnimated:NO];

I saw some thing similar today where the view did not update after pop