如何在第一次查看时隐藏 UINavigationBar
我想隐藏仅在第一个视图中自动加载导航项目的 UINavigationBar,并且想知道如何才能完成这项工作。
我尝试这样做
//RootViewController.m
#import "mydelegate.h" //-- this is where the view controller is initialized
//...
- (void)viewDidLoad
{
[super viewDidLoad];
navigationController *navController = [[navigationController alloc] init];
[navigationController setNavigationBarHidden:YES animated:animated];
}
//.....
但是我收到错误,因为我想我没有正确地从委托文件中调用 navigationController 或者这不可能像来自另一个类的方法那样调用它。
任何帮助将不胜感激。
I am wanting to hide the UINavigationBar that automatically loads with the Navigation project for the first view only and am wondering how I can make this work.
I have tries to do it like this
//RootViewController.m
#import "mydelegate.h" //-- this is where the view controller is initialized
//...
- (void)viewDidLoad
{
[super viewDidLoad];
navigationController *navController = [[navigationController alloc] init];
[navigationController setNavigationBarHidden:YES animated:animated];
}
//.....
However I am getting errors because I guess I am not calling navigationController across from the delegate file properly or this is just not possible to call it like you would a method from another class.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里有一些问题。
self.navigationController
访问呈现视图控制器的导航控制器。您的代码片段正在创建一个新的 UINavigationController;隐藏那个酒吧不会给你带来任何好处。viewDidLoad
中,而应将其隐藏在viewWillAppear:
中。您可以在 viewDidLoad 中隐藏导航栏,并且当视图最初呈现时导航栏将被隐藏,但是如果您要推送另一个呈现导航栏的视图并点击后退按钮,导航栏将保持可见。您的
viewWillAppear:
应该看起来像这样:并且您在此导航控制器上推送的其他视图控制器中的
viewWillAppear:
方法应该适当地显示或隐藏导航栏。There are a couple things wrong here.
self.navigationController
. Your code snippet is creating a new UINavigationController; hiding that bar won't get you anything.viewDidLoad
, you should hide it inviewWillAppear:
. You can hide the navigation bar inviewDidLoad
, and the navigation bar will be hidden when the view is initially presented, but if you were to push another view that presented the navigation bar and hit the back button, the navigation bar would remain visible.Your
viewWillAppear:
should look something like this:And the
viewWillAppear:
methods in other view controllers you push on this navigation controller should show or hide the navigation bar appropriately.您是否正在访问 UINavigationController 的正确实例?
您可以通过 self.navigationController 从已添加到其堆栈的任何 UIViewController 访问 UINavigationController。
否则,也许这会有所帮助:
iPhone 仅在首页隐藏导航栏
Are you accessing the correct instance of the UINavicationController?
You can access the UINavigationController via self.navigationController from any UIViewController that's been added to its stack.
Otherwise, maybe this'll help:
iPhone hide Navigation Bar only on first page
iPhone 仅在首页隐藏导航栏 尝试这个答案
。它为我解决了问题。
我也遇到了导航栏的问题。我可以让它消失,但我无法让它在需要的时候重新出现。此链接解释了如何解决此问题,只需在 viewWillAppear 中打开它,并在 viewWillDisappear 中关闭它即可。
iPhone hide Navigation Bar only on first page
Try this answer. It solved the problem for me.
I was having the problem with the navigation bar as well. I could make it disappear, but I couldn't make it reappear when it needed to. This link explains how you can solve this problem, simply by turning it on in viewWillAppear, and off in viewWillDisappear.