xcode setNavigationBarHidden:YES 不适用于 searchDisplayController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8950541/
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-14 23:03:15  来源:igfitidea点击:

setNavigationBarHidden:YES doesn't work with the searchDisplayController

iphonexcodeuisearchdisplaycontroller

提问by sora

I'm using the following code to hide my navigationBar in the detailViewController(my second view), and it works perfectly fine when I tap any of my object from the MasterViewController(my first view).

我正在使用以下代码在 detailViewController(我的第二个视图)中隐藏我的导航栏,当我从 MasterViewController(我的第一个视图)点击我的任何对象时,它工作得非常好。

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

However, when I filter the table list in the masterViewController using searchDisplayController and tap any object from the result, the navigationBar in the detailView doesn't get hidden...

但是,当我使用 searchDisplayController 过滤 masterViewController 中的表列表并点击结果中的任何对象时,detailView 中的导航栏不会隐藏...

Do I have to do any extra work to hide the navigationBar if I use the searchDisplayController?

如果我使用 searchDisplayController,是否需要做任何额外的工作来隐藏导航栏?

for Debug, I set the break point on the line of setNavigationBarHidden:YES, and even if I go to the detailViewController via search result, the application hits the line..

对于Debug,我在setNavigationBarHidden:YES这一行设置了断点,即使我通过搜索结果进入detailViewController,应用程序也碰到了该行..

回答by jt6562

you shuold put [self.navigationController setNavigationBarHidden:YES]; in viewWillLayoutSubviews function.like this:

你应该把 [self.navigationController setNavigationBarHidden:YES]; 在 viewWillLayoutSubviews 函数中。像这样:

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

it works.

有用。

回答by CFIFok

You should try this method:
In that controller, where you declared UISearchController *searchController, you should implement two methods (only for example):

您应该尝试这种方法:
在您声明的那个控制器中UISearchController *searchController,您应该实现两个方法(仅作为示例):

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // if you want to hide Navigation Bar when searchController will become active
    _searchController.hidesNavigationBarDuringPresentation = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    _searchController.hidesNavigationBarDuringPresentation = NO;
}

The code above may have differences. Main point in hidesNavigationBarDuringPresentationproperty (iOS 8.0 and later). Try to play with it, and turn to hidesNavigationBarDuringPresentation = NObefore pushing a new controller. After this manipulations I took profit: when pushed UIViewController, setter setNavigationBarHidden:YESbecome working

上面的代码可能有差异。hidesNavigationBarDuringPresentation属性中的要点(iOS 8.0 及更高版本)。尝试使用它,并hidesNavigationBarDuringPresentation = NO在推送新控制器之前转向。在这个操作之后我获利了:当推送 UIViewController 时,settersetNavigationBarHidden:YES开始工作

回答by Apple

if you want to hide Navigation bar then, In your MainWindow xib uncheck "Shows Navigation Bar" attributes of Navigation Controller.

如果您想隐藏导航栏,请在您的 MainWindow xib 中取消选中导航控制器的“显示导航栏”属性。

This Will hide the Navigation Bar in your Whole Project. If you want to Show Navigation Bar in any Controller set NavigationBar Hidden = NO in ViewDidLoad Method of that Controller.

这将隐藏整个项目中的导航栏。如果要在任何控制器中显示导航栏,请在该控制器的 ViewDidLoad 方法中设置 NavigationBar Hidden = NO。

回答by Hashem Aboonajmi

you should hack search display controller in some way to hide its built in navigationBar.

您应该以某种方式破解搜索显示控制器以隐藏其内置导航栏。

here is the answer:

这是答案:

https://stackoverflow.com/a/6337037/1348121

https://stackoverflow.com/a/6337037/1348121

回答by ymutlu

This

这个

- (void) viewWillLayoutSubviews

causes layout problems, so i used code below. Works fine for me.

导致布局问题,所以我使用了下面的代码。对我来说很好用。

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