Take the 2-minute tour ×

I have the following code:

NSArray* stack = self.navigationController.viewControllers;
NSArray* newStack = @[stack[0], stack[2]];
[self.navigationController setViewControllers:newStack animated:NO];

stack contains 3 view controllers. The problem is that the navigation bar is not removing UINavigationItems to match, so self.navigationController.navigationBar.items.count still returns 3 after running this code. Going back gets you into a weird state where you have a back button at the top that you can press but it just disappears, not taking you back any further.

Is this a bug in iOS 7 or am I just trying to do something really stupid? What's the best way to fix or work around this?

share|improve this question
Any answers or fixes? –  nicktmro Sep 30 '13 at 21:00

2 Answers 2

The behavior you are describing is a corrupt navigation controller stack. This is probably because you are trying to use a navigationController improperly. I don't have much context from the code here, but I am guessing you are trying to skip back to your root view controller? I think this is probably more what you would need:


you will then want to add a custom back button with something like so:

UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(yourMethodToPopToRoot)];
//yourMethodToPopToRoot is a method you create that runs popToRootViewController
self.navigationItem.leftBarButtonItem = backButton;

Any questions let me know.

share|improve this answer

The navigationBar has its own ‘items’ stack which is not updated until viewDidAppear hits.

Which means, if we recreate the navigation controllers’ stack in viewDidLoad using i.e. setViewControllers: when we get to viewDidAppear we will have the current item added to the bars’ ‘items’ stack and therefore the UINavController viewController stack will not be in sync with the UINavBar items stack. This appears to be an iOS 7 bug.

In iOS 6.0 the 2 different stacks do not get out of sync no matter where we set the new viewControllers stack.

So try moving your code in viewDidAppear and see if that fixes the problem. I bet it will, because for me it did.

share|improve this answer

Your Answer


