xcode 在 Storyboard 中隐藏一个 ViewController 的 NavigationBar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13167520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:58:48  来源:igfitidea点击:

Hide NavigationBar for one ViewController in Storyboard

iphoneiosxcodeuinavigationcontrollernavbar

提问by Siriss

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. Here is my storyboard:

我找到了很多帖子,但仍然没有解决方案。我试图在初始上隐藏 NavigationBar UIViewController,但我仍想在第二个上显示它UIViewController。这是我的故事板:

enter image description here

在此处输入图片说明

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. When I do the same in to the NavigationBar in NavController, it disappears for all three (because they all inherit the no Nav Bar).

当我关闭主视图控制器的推断顶栏时,它会在 Storyboard 中消失,但在我运行应用程序时它仍然显示。当我对 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. Let me know if you need to see anything else. Thank you much!

所有控制器都有相应的 .h 或 .m 文件,但我对如何以编程方式执行此操作感到困惑。如果您需要查看其他内容,请告诉我。非常感谢!

回答by user427969

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

回答by keji

If you want to keep things in the Storyboard than edit the User Defined Attributes and set navigationController.navigationBarHiddenas a Boolean checked.

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

回答by instanceof

Anyone wanting to know how to do this in Swift?

有人想知道如何在 Swift 中做到这一点吗?

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

回答by whiteagle

self.navigationController.navigationBarHidden = YES;

回答by Remixed123

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