UINavigationController setViewController: animated: problems with the navigation bar

I have an incredibly unpleasant problem that seems like a mistake, but it’s really hard for me to believe that no one else has come across this. My application root view controller is a UITabBarController where each tab is a UINavigationController. Everything works great.

Now I come to the place where I want to edit the stack, so I rearrange the viewControllers of the current navigation controller, and then do:

[self.navigationController setViewControllers:newViewControllers animated:YES]; 

The stack is correctly pushed out / pushed to the top-level controller, but the navigation bar does not update to the current view controller and seems to remain the same as with the viewController before the pop. If I do this:

 [self.navigationController popToViewController:someViewController animated:YES]; 

Everything works perfectly. Has anyone ever come across this before? Is there a workaround? Am I doing something wrong?

+6
iphone uiviewcontroller uinavigationcontroller
source share
5 answers

Apple seems to have fixed this in the latest SDK

+2
source share

I had the same problem, it seems that Apple did not fix this error, and as a result, the selected answer of this stream turned out to be incorrect. I was able to fix this problem using this bug report , as in Anurag's comment combined with Scott Pfeil's comment.

Here is the code:

 navController.navigationBarHidden = YES; NSArray* viewControllers = navController.viewControllers; UIViewController* currentController = [viewControllers objectAtIndex:viewControllers.count-1]; NSArray *controllers = [NSArray arrayWithObjects: viewController , currentController , nil]; [navController setViewControllers:controllers animated:NO]; navController.navigationBarHidden = NO; 

I call this code in the viewDidLoad currentController , and what I did replaces the previous controllers with only the viewController .

Hope this helps.

+4
source share

Two equally ugly work.

Firstly, if:

 [self.navigationController popToViewController:someViewController animated:YES]; 

Works well, try pushing an additional view manager on the stack, and then call:

 [self.navigationController popToViewController:someViewController animated:NO]; 

The value you should get in the vc that you want without any animation.

Secondly,

Before installing the stack, set the value leftButtonBarItem = nil; Effectively remove the old view controller button. In fact, if the name is incorrect, change that too.

None of them are pure, but can give you the desired results.

+1
source share

You can also configure the root view controller as a UINavigationController delegate, for example:

 @interface YourViewController : UIViewController <UINavigationControllerDelegate> { 

and then in the didShowViewController delegation method, you manually set the available view controllers:

 -(void)navigationController:(UINavigationController*)navigationController didShowViewController:(UIViewController*)viewController animated:(BOOL)animated { [[viewController navigationController] setViewControllers:[[viewController navigationController] viewControllers]]; } 

Let me know if this works in your environment!

0
source share
 [self.navigationController setViewControllers:newViewControllers animated:NO]; 

it can help you.

-2
source share

All Articles