故事板 - 以编程方式隐藏导航控制器的顶部栏 [英] Storyboard - Hiding top bar of navigation controller programmatically

查看:155
本文介绍了故事板 - 以编程方式隐藏导航控制器的顶部栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用故事板,当我按下某个按钮(或调用函数)时,我正试图隐藏主导航控制器的顶部栏。我知道我必须从故事板(使用标识符)初始化一个引用导航控制器的对象,但是当我将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];

这篇关于故事板 - 以编程方式隐藏导航控制器的顶部栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆