When using popToRootViewController I lose my navig

2019-07-24 18:15发布

问题:

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!

回答1:

In viewWillAppear of your rootViewControler

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