Idan
Idan

Reputation: 5827

How to push UIViewController with Nav while inside View Controller without nav bar

I'm showing UINavigationController modally. For the root view controller, I don't want to show the Navigation bar.

However for deeper controllers, I do want to show it.

I though of doing something like this inside my root view controller :

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

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

However, this presents issues, when I go back from the first view controller to the root view controller. The navigation bar is disappearing after pressing the "back" button (inside the first view controller, leaving white space), and not only after the rootViewController finished loading. (Obviously because my code uses viewWillAppear)

Is there a solution for it ?

The only thing I thought of is hidiing the navigation bar permanently, and adding Navigation bar manually to each view controller in the stack. I hope not to do that since it's much more work, and moreover, I want to use arrow shaped buttons, for which I would have to create custom images.

Appreciate any suggestions.

Upvotes: 0

Views: 736

Answers (1)

Luke Fletcher
Luke Fletcher

Reputation: 348

This should do it, I haven't tested it out, but should work in theory:

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

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

Upvotes: 1

Related Questions