I'm using this code to show a 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];
and the viewController is displayed correctly. Then I'm using this code to prepare an animation (Used to animate the pop):
CATransition *transition = [CATransition animation];
transition.duration = 0.f;
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
However, neither of these lines will pop it:
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:NO];
What could be the issue? Logging the navigation stack displays both the correct UIViewControllers
:
NSLog(@"%@", self.navigationController.viewControllers);
Ok, so this is embarrassing.
I was running the push call in the viewDidAppear:animated:
, and I had forgotten to implement a check if we had already pushed. So when I popped the new UIViewController
, the viewDidAppear:animated
re-pushed the new VC again. I also set the it to animate:NO
and removed the custom transition, causing the pop and re-push to happen basically instantaneously.
I discovered this by putting a breakpoint at the pop message, and noticed the simulator displayed the root UIViewController
for a fraction of a second.