故事板 - 以编程方式隐藏导航控制器的顶部栏
我正在使用故事板,当我按下某个按钮(或调用函数)时,我正试图隐藏主导航控制器的顶部栏。我知道我必须从故事板(使用标识符)初始化一个引用导航控制器的对象,但是当我将setNavigationBarHidden消息发送到这个新创建的对象时,屏幕上没有任何实际发生。
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];
有谁知道问题是什么?
终于解决了。您应该始终只通过viewController隐藏导航栏。
Finally solved it. You should always hide navigation bar only through viewController.
在我上面的问题中,我实例化了一个全新的navigationController,它没有指向屏幕上真正的navController。你可以通过视图控制器获得真实的,如下所示:
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];