penguin-penpen penguin-penpen - 6 months ago 39
Objective-C Question

UINavigationController.navigationBar setHidden:NO doesn't work?

I have a

HomeViewController
and it has a property
searchViewController
.

HomeViewController
is the delegate of
searchViewControllerDelegate
so that I can pop
searchViewController
when I click a button in
searchViewController.view
(I use
pushViewControllerAnimated:
to push
searchViewController
into view controller stack.

I want to show the
navigationBar
when the
searchViewController
is popped up.

However

[self.navigationController.navigationBar setHidden:NO];


is definitely not working.

I've checked that the navigationBar is not
nil
so I can't figure out what the problem might be.

actual code

#pragma mark - HomeTabSearchTableViewDelegate
-(void)parentViewControllerPop{
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController.navigationBar setHidden:NO];
}


searchViewController
is popped up successfully, just the navigationBar problem.

Answer

on your HomeViewController

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

    //or use like
   // [[self navigationController] setNavigationBarHidden:NO animated:YES];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:YES];    // hides

      //or use like
   // [[self navigationController] setNavigationBarHidden:YES animated:YES];
}