Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using popToRootViewController I lose my navigation bar

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.

ScreenShot

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!

like image 203
Ben Avatar asked Mar 23 '23 15:03

Ben


1 Answers

In viewWillAppear of your rootViewControler

-(void)viewWillAppear:(BOOL)animated{
   [self.navigationController setNavigationBarHidden:NO];
}
like image 78
LE SANG Avatar answered Apr 26 '23 03:04

LE SANG