1
votes

I have a UIViewController (let's call it VC0) in a UINavigationController. VC0 makes use of a UISearchDisplayController to display results in a UITableView from a search. After the user selects a table cell from the search results, it pushes another UIViewController (call it VC1).

In both VC0 and VC1, I have set navigationBarHidden to YES. However, when I select the table cell and VC1 is pushed, I still see the navigation bar on top of VC1 with a back button to VC0.

How do I permanently hide the navigation bar in VC1?

Update:

The navigation bar disappears if I put the following line in viewDidAppear:, but it is still visible before it is hidden.

self.navigationController.navigationBarHidden = YES;

But if I put it in viewDidLoad or viewWillAppear:, it doesn't work. Any reason why?

1
You want to hide Navigationbar on both ViewControllers? - Vivek Molkar
@VivekMolkar Yes. I am able to hide it in VC0 but not in VC1. - Sudeep
How are you pushing VC1? push Segue? - Vivek Molkar
@VivekMolkar nope, through the navigation controller. [self.navigationController pushViewController:VC1 animated:YES]; - Sudeep

1 Answers

0
votes

Make a simple ViewController as a name BaseViewController. and make your both VC0 and VC1 is derived from BaseViewController. and simply set your navigationBarHidden to YES in BaseViewController.

this will applicable to VC0 and VC1 by simple one line of code.

  1. @interface BaseViewController : UIViewController

  2. @interface VC0 : BaseViewController

  3. @interface VC1 : BaseViewController

like this

and BaseViewController's method

 - (void)viewDidLoad
 {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden=YES;
 }