Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar doesn't show up

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.

like image 904
javal88 Avatar asked Oct 15 '13 10:10

javal88


2 Answers

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:

like image 89
hybridcattt Avatar answered Sep 20 '22 10:09

hybridcattt


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

like image 40
Firo Avatar answered Sep 22 '22 10:09

Firo