I have a UINavigationController and I in the current top-of-stack controller, I want to push a new controller on and then remove the current VC. In short, the goes from
[ViewController A]
[ViewController B]
to
[ViewController A]
[ViewController B]
[ViewController C]
to
[ViewController A]
[ViewController C]
I accomplish this in VC B by:
[self.navigationController pushViewController:VCC animated:YES];
[self removeFromParentViewController];
Works fine EXCEPT that the navigationItem stack still has the title/backButton from VC B sandwiched between A and C.
How can I remove a VC from the UINavigationController stack AND ALSO update the navigationItem stack?
The Navigation item did not show up because of the "style" of placing/removing the viewcontroller.
Instead of [self removeFromParentViewController] use [[self navigationController] popViewControllerAnimated:NO] twice first before pushing the newviewcontroller onto the navigationcontroller
Another way is:
NSMutableArray *VCs = [self.navigationController.viewControllers mutableCopy];
[VCs removeObjectAtIndex:[VCs count] - 2];
self.navigationController.viewControllers = VCs;
Have a look at this: How do I pop the view controller underneath a pushed view controller?
Give it a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With