Hiding the UINavigationBar for the root UIViewController only

I use the UINavigationController (side of the note: inside the UITabBar), which by default gives you the UINavigationBar on top. If I hide the panel through IB, the panel will disappear not only for the root UIViewController, but for all the controllers that I click on the stack. Leaving me no (automatic) way to weave.

So, how can you hide the UINavigtionBar only in the root UIViewController. Turning on / off "navigationBarHidden" temporarily does not work, as it looks uncomfortable with the animation.

Any other ideas?

+5
source share
4 answers

, , UINavigationCOntroller, UINavigationController ,

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if([viewController isKindOfClass: [SomeClass class]])
        [self setNavigationBarHidden: NO];
    else
        [self setNavigationBarHidden: YES];
}

, , , , , ... ,

+5

, UInavigationBar, - UInaviagtionBar .

 -(void)viewWillDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

: self.navigationController.navigationBarHidden = YES; .

+8

, . , TableViewController, , , UINavigationController .

, . .

0

, . , UITAbBar, , , viewDidAppear: , , -, , .

Assuming you are handling this, one option is to change navigationBarHidden after you have animated. There is no good place to process along the way, as you want pop animation to happen after the bar animation. The quickest solution is to hide the panel, and then manually run runloop for ~ 0.5 seconds, until it comes to life, and then continues. It is important, but it is fast and it works.

- (void)viewWillDisappear:(BOOL)animated {
  if (animated) {
     [self.navigationController.navigationBar setHidden:YES animated:YES];
  }

  //GROSS
  NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:0.5];
  while([[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:endDate]);
}

If you want to do this cleanly, I recommend re-executing the UINavigationController from scratch.

0
source

All Articles