Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

ios - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...