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?
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.
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