3

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?

Thompson
  • 1,098
  • 11
  • 25

1 Answers1

3

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.

Community
  • 1
  • 1
lakshmen
  • 28,346
  • 66
  • 178
  • 276
  • thanks for the reply. The two-pops-and-a-push method doesn't work; both pops happen but the push never does. The NSMutableArray method "works" in that the VCs and the navBar are in sync, but the app complains "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted." Good news is that it doesn't get _seem_ to get corrupted so I think I can live with this! – Thompson Jul 07 '13 at 06:11