Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;  } 
like image 935
kingston Avatar asked Feb 11 '12 09:02

kingston


People also ask

How do I hide navigation controller?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I remove a view controller from navigation stack?

Use this code and enjoy: NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self. navigationController. viewControllers]; // [navigationArray removeAllObjects]; // This is just for remove all view controller from navigation stack.


1 Answers

Try this method inside a view controller:

// swift self.navigationController?.setNavigationBarHidden(true, animated: true)  // objective-c [self.navigationController setNavigationBarHidden:YES animated:YES];  

More clarifications:

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

Let's look at the next hierarchy:

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

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

- (void)viewWillAppear:(BOOL)animated {     [super viewWillAppear:animated];     [self.navigationController setNavigationBarHidden:YES animated:YES];   //it hides the bar }  - (void)viewWillDisappear:(BOOL)animated {     [super viewWillDisappear:animated];     [self.navigationController setNavigationBarHidden:NO animated:YES]; // it shows the bar back } 
like image 169
beryllium Avatar answered Oct 02 '22 08:10

beryllium