简体   繁体   English

在 Storyboard 中隐藏一个 ViewController 的 NavigationBar

[英]Hide NavigationBar for one ViewController in Storyboard

I have found many posts, but still no solution.我找到了很多帖子,但仍然没有解决方案。 I am trying to hide a NavigationBar on the initial UIViewController , but i want to still show it on the second UIViewController .我试图在初始UIViewController上隐藏一个 NavigationBar ,但我仍然想在第二个UIViewController上显示它。 Here is my storyboard:这是我的故事板:

在此处输入图片说明

When I turn off the Inferred Top Bar for my Main View Controller, it disappears in Storyboard, but it still shows when I run the app.当我关闭主视图控制器的 Inferred Top Bar 时,它会在 Storyboard 中消失,但在我运行应用程序时它仍然显示。 When I do the same in to the NavigationBar in NavController, it disappears for all three (because they all inherit the no Nav Bar).当我对 NavController 中的 NavigationBar 执行相同的操作时,它对所有三个都消失了(因为它们都继承了无导航栏)。

I want to show the NavBar in ScrollViewV View Controller, but have it hidden in MainViewController .我想在 ScrollViewV 视图控制器中显示 NavBar,但将它隐藏在MainViewController

All Controllers have the corresponding .h or .m files, but I am confused on how to do this programmatically.所有控制器都有相应的 .h 或 .m 文件,但我对如何以编程方式执行此操作感到困惑。 Let me know if you need to see anything else.如果您需要查看其他内容,请告诉我。 Thank you much!非常感谢!

In your mainViewController, you can do following:在您的 mainViewController 中,您可以执行以下操作:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

You might want to show the Navigation bar when hiding this ViewController, for that do the following:您可能希望在隐藏此 ViewController 时显示导航栏,为此请执行以下操作:

- (void)viewDidDisappear: (BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewDidDisappear:animated];
}

如果你想在 Storyboard 中保留东西而不是编辑用户定义的属性并将navigationController.navigationBarHidden设置为一个布尔值检查。

self.navigationController.navigationBarHidden = YES;

I noticed that you also need to add the following to the controller that you do want the navigation to appear.我注意到您还需要将以下内容添加到您希望导航出现的控制器中。

[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillAppear:animated];

Anyone wanting to know how to do this in Swift?有人想知道如何在 Swift 中做到这一点吗?

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    self.navigationController?.navigationBar.hidden = true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM