Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboard - Hiding top bar of navigation controller programmatically

I'm using a storyboard and I'm trying to hide a top bar of my main navigation controller when a certain button is pressed (or function is called). I know I have to initialize an object referring to a navigation controller from a storyboard (using identifiers), but when I send the setNavigationBarHidden message to this newly created object nothing really happens on screen.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UINavigationController *navController = (UINavigationController*) [storyboard instantiateViewControllerWithIdentifier:@"MyNavController"];  [navController setNavigationBarHidden:YES animated:YES]; 

Does anyone know what the problem is?

like image 640
animal_chin Avatar asked Nov 21 '11 17:11

animal_chin


People also ask

How do I hide navigation bar in Swift storyboard?

Click on the controller that has the top bar navigate to the properties bar on the right hand side of Xcode. There is a drop down labeled Top Bar (as shown above) change this drop down to none.

How do I hide the navigation bar?

Way 1: 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 hide the top navigation bar in Swift?

To hide the navigation bar in Swift, you'll need to add code to two methods: viewWillAppear and viewWillDisappear . That's it to hide the navigation bar in your view controller.

How do I embed a view controller in navigation controller storyboard?

In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .


1 Answers

Finally solved it. You should always hide navigation bar only through viewController.

In my question above I instantiated a whole new navigationController which didn't point at the real navController on the screen. You can obtain the "real" one through the view controller like this:

[viewController.navigationController setNavigationBarHidden:YES animated:YES]; 
like image 187
animal_chin Avatar answered Sep 17 '22 15:09

animal_chin