kingston kingston - 1 month ago 16
iOS Question

How to hide a navigation bar from one particular view controller

I've created a two splash screen iPhone app. Afterwards user is taken to first view. I've added a UINavigationController. It works perfectly fine.

How do I remove the navigation bar for the opening view alone?

MainWindow

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


self.splashScreen = [[SplashScreen alloc]
initWithNibName:@"SplashScreen"
bundle:nil];
if (self.pageController == nil) {
openingpage *page=[[openingpage alloc]initWithNibName:@"openingpage" bundle:[NSBundle mainBundle]];
self.pageController = page;
[page release];
}
[self.navigationController pushViewController:self.pageController animated:YES];

[window addSubview:splashScreen.view];

[splashScreen displayScreen];
[self.window makeKeyAndVisible];

return YES;
}

Answer

Use this method:

[self.navigationController setNavigationBarHidden:YES animated:YES];

So, if you are in some view controller:

[self.navigationController setNavigationBarHidden:YES animated:YES];

More clarifications:

UINavigationController has a property navigationBarHidden, that allows you to hide/show navigation bar for whole nav controller.

Let's loot at the next hierarchy:

--UINavigationController
------UIViewController1
------UIViewController2
------UIViewController3

Each of three UIViewController will have nav bar since they are in UINavigationController. For example, you want to hide bar into the second (actually it doesn't matter in which one), then write into UIViewController2:

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

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