Navigation bar doesn't show up

11,424

Solution 1

If you want StartViewController to hide navigation bar, and DestinationViewController to show it: Add corresponding code to -(void)viewWillAppear: method.

StartViewController:

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

DestinationViewController:

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

If you want both view controllers to have navigation bar, just remove all lines that contain setNavigationBarHidden:

Solution 2

You problem here is that your viewDidLoad is being called before your viewWillDisappear. You must load a new view before you can unload the parent (visually). So you are setting the nav bar visible and hiding it again.

Navigation bars are universal between the views nested inside of it. There really should be no reason to hide it when a view is disappearing unless the childview view does not need it. If you further explained what you are attempting to do we can help more. But in the mean time if you just remove your viewWillDisappear implementation (at least what you are showing us) you should be good. Otherwise you can set the hidden property to no in your DestinationViewController's viewWillAppear or viewDidAppear (depending on the calling order).

Share:
11,424
javal88
Author by

javal88

BY DAY: Tech enthusiast BY NIGHT: Drummer HOBBIES: Music, drumming, trekking, nerding #SOreadytohelp

Updated on July 24, 2022

Comments

  • javal88
    javal88 almost 2 years

    I have this problem: i have a view controller (embedded in a navigation controller) that after doing an action triggers a manual segue pushing a new view controller, however in the new view controller there is no navigation bar because in the first controller i had implemented the viewWillDisappear method like this:

    StartViewController

    - (void)viewWillDisappear:(BOOL)animated {
      // Hide the navigation bar just before the view disappear
      [[self navigationController] setNavigationBarHidden:YES animated:YES];
    }
    

    Here is the code for the manual segue that's inside an IBAction:

    [self performSegueWithIdentifier:@"tutorialSegue" sender:self];
    

    DestinationViewController

    I'd tried like this

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view.
        [[self navigationController] setNavigationBarHidden:NO animated:NO];
    }
    

    but it doesn't work, actually in the debugger i noticed navigationcontroller is equal to nil and i just can't figured out why.

  • javal88
    javal88 over 10 years
    You're right, actually i have another view controller right before the startViewController without navigationBar. If i had not used the viewWillDisappear solution in the startViewController, when i switched back, its navigation bar remained on screen. Sorry for my english
  • Firo
    Firo over 10 years
    Then in that view controller (the one before startViewController) hide the navigation bar in its viewWillAppear (so every controller states whether it wants the navigation bar or not). That way whenever you go back to it, it is hidden! Also your English is really, I would have never guessed it wasn't your first language!
  • bickster
    bickster over 9 years
    Can this be done by using the Storyboard and not programically?
  • hybridcattt
    hybridcattt almost 9 years
    Please note that this is old answer, since iOS7 it is advised to use (override) prefersStatusbarHidden.