Storyboard - Hiding top bar of navigation controll

2019-01-31 19:25发布

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?

8条回答
走好不送
2楼-- · 2019-01-31 19:35

In Xamarin.iOS

base.NavigationController.NavigationBarHidden = true;
查看更多
Bombasti
3楼-- · 2019-01-31 19:35

SetRoot RootViewController after Changing the Properties.

  UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

// Create Navigation controller with RootViewController
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[storyBoard instantiateViewControllerWithIdentifier:@"MyRootViewController"]];

Setting RootViewController

 [appDelegate.window setRootViewController: navController];

or else you Can Do in any ViewController

[self.navigationController setNavigationBarHidden:YES animated:YES];
查看更多
乱世女痞
4楼-- · 2019-01-31 19:36

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];
查看更多
Evening l夕情丶
5楼-- · 2019-01-31 19:42

I faced same problem, this worked for me

navController.navigationBar.hidden = YES;

查看更多
爷的心禁止访问
6楼-- · 2019-01-31 19:43

There are 2 ways to hide top bar of Navigation Controller:

1) Programatically

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

2) Using Interface Builder

You can uncheck "Shows Navigation Bar" in property list of Navigation Controller.

enter image description here

Please make sure you have selected scene which contain Navigation Controller. Example image of scene.
enter image description here

查看更多
你好瞎i
7楼-- · 2019-01-31 19:43

I hide my Navigation bar by unchecking Bar Visibility "Shows Navigation Bar" In Attribute Inspector.Hope this help someone.

enter image description here

查看更多
登录 后发表回答