在UISearchDisplayController选择之后保持UINavigationController的navigationBar隐藏 [英] Keeping UINavigationController's navigationBar hidden after UISearchDisplayController selection

查看:256
本文介绍了在UISearchDisplayController选择之后保持UINavigationController的navigationBar隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UISearchDisplayController 设置,其中包含 UITableViewController ,它嵌套在 UINavigationController 。当选择一个单元格时,会触发 UITableView的 didSelectRowAtIndexPath 方法,这会将新视图推送到父导航控制器。这个新视图应该在输入时隐藏导航栏。

I have a UISearchDisplayController setup with a UITableViewController which is nested inside a UINavigationController. When a selection of a cell is made, UITableView's didSelectRowAtIndexPath method is triggered, which pushes a new view to the parent navigation controller. This new view should have the navigation bar hidden on entry.

[[self navigationController] setNavigationBarHidden:YES animated:NO];

我在 didSelectRowAtIndexPath 方法中使用此行隐藏导航栏。当选择不使用搜索控制器的行但在选择搜索结果时被覆盖时,这可以正常工作。似乎 UISearchDisplayController 在选择行之后的某个时间取消了导航栏的权利。

I use this line in the didSelectRowAtIndexPath method to hide the navigation bar. This works fine when a row is selected not using the search controller, but is overridden when selecting a search result. It seems the UISearchDisplayController takes it in its right to un-hide the navigationBar sometime after the row is selected.

如果我将 setNavigationBarHidden 调用移动到目标视图的 viewWillAppear 方法,结果类似。我可以通过将隐藏调用放在 viewDidAppear 中来实现它,但这会产生一个非常尴尬的过渡效果,它会让人觉得有些不合时宜。我想在新视图滑到屏幕之前使navigationBar已经隐藏。

If I move the setNavigationBarHidden call into the target view's viewWillAppear method, results are similar. I can make it work by placing the hide call in viewDidAppear, but this makes for a very awkward transition effect which feels jumpy and out of place. I would like to make the navigationBar already hidden before the new view slides on to the screen.

有没有人知道导航栏的取消隐藏在哪里,和/或任何我可以覆盖这种行为吗?

Does anyone know where the unhiding of the navigationBar is occurring, and/or any way I can override this behaviour?

推荐答案

这可能不是最优雅的解决方案,但我相信它确实是你的'我想要它。我遇到了类似的问题,我的解决方案是有一个隐藏导航栏的方法,该方法在延迟0秒后调用,如下所示。

This may not be the most elegant solution, but I believe it does exactly what you'd want it to. I came across a similar problem, and my solution was to have a method which hides the navigation bar, which is called after a delay of 0 seconds as follows.

方法被称为:

-(void) hideNavBar {
    if (self.navigationController.navigationBar.hidden == NO)
    {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }
}

然后在viewDidLoad方法中,我有以下内容:

Then in the viewDidLoad method, I have the following:

[self performSelector:@selector(hideNavBar) withObject:nil afterDelay:0.0];

这可以在一瞬间移除导航栏。如果您想要动画,可以修改延迟时间,或者在延迟后删除它。我试过[self hideNavBar],但这根本不起作用,所以坚持我上面的内容。

This works and removes the navigation bar in one instantaneous swoop. You can amend the delay time if you want the animation or for it to be removed after a delay. I tried [self hideNavBar] but that simply did not work, so sticking to what I have above.

希望这会有所帮助,如果有人有更优雅的解决方案,我感兴趣!

Hope this helps, and if someone has a more elegant solution, I'm interested!

这篇关于在UISearchDisplayController选择之后保持UINavigationController的navigationBar隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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