javal88
javal88

Reputation: 1248

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.

Upvotes: 9

Views: 11602

Answers (4)

Gajendrasinh Chauhan
Gajendrasinh Chauhan

Reputation: 3397

If your code is looks like

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

change it to,

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

type "super viewWillappear..." before "self.nav..."

Upvotes: 0

Ed Manners
Ed Manners

Reputation: 559

Just another angle on this: When in the storyboard editor, I reset the initial view controller by accident (in the properties pane), as a result I lost the navigation bar. Simply resetting the Navigation Controller as "Is Initial View Controller" brought it back.

Upvotes: 0

Firo
Firo

Reputation: 15566

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

Upvotes: 1

hybridcattt
hybridcattt

Reputation: 3041

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:

Upvotes: 12

Related Questions