当使用popToRootViewController时,我会丢失导航栏 [英] When using popToRootViewController I lose my navigation bar
问题描述
我有一个iOS应用程序,其中主屏幕是UICollectionViewController.当从集合视图中选择一个项目时,该视图将被推到该项目的详细视图.在详细视图中,我构建了一个从侧面移出的抽屉/滑块.为了使视图看起来像我想要的样子,我隐藏了默认导航栏,并通过情节提要插入了一个导航栏.
I have an iOS app where the main screen is a UICollectionViewController. When selecting an Item from the collection view the view is pushed to a detail view of the item. In the detail view I built a drawer/slider that moves out from the side. In order to get the view to look the way I wanted I hid the default navigation bar and inserted one via storyboards.
我遇到一个问题,当隐藏默认导航栏时,您将丢失使用导航控制器随附的后退按钮功能.为此,我添加了一个后退按钮(在上面的图像中未显示该按钮)的按钮来解决此问题.现在,我使用下面的代码行移回到集合视图.
I ran into an issue that when hiding the default navigation bar you lose the back button functionality that comes with using a navigation controller. I worked around this by adding a button where the back button would have been (the image above is shown without the button). Now I use the line of code below to move back to the collection view.
[self.navigationController popToRootViewControllerAnimated:YES];
它以我想要的方式工作,除了返回到集合视图时丢失导航栏.是否有人对如何解决此问题有任何想法?提前致谢!
It works the way I want it except that I lose my Navigation Bar when I return to the collection view. Does anyone have any thoughts on how to fix this? Thanks in advance!
推荐答案
在您的rootViewControler的viewWillAppear中
In viewWillAppear of your rootViewControler
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO];
}
这篇关于当使用popToRootViewController时,我会丢失导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!