Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
Hi all,

In my app have a navigation controller with 2 view controller : FirstViewController, SecondViewController. In the FirstViewController, I need show the navigation bar but hide it in SecondVieController. Since by default the navigation bar is not hidden, so I didn't set the navigationBarHidden status in FirstViewController and just let it displayed on the first view.

In the SecondViewController, since I need hide it so I set navigationBarHidden property in SecondViewController's viewWillAppear and ViewWillDisappear method as below:

SecondViewController.m
Code:
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    [super viewWillAppear:animated];
}

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

- (IBAction)backToFirstVC:(id)sender 
{
    [self.navigationController popViewControllerAnimated:NO];
}

And it works fine, I can hide the navigation bar in SecondViewController. The SecondViewController consists a custom UIButton which used to pop out the SecondViewController and back to FirstViewController. So, what happened is when I click this button and back to FirstViewController, the navigation bar does not appear in FirstViewController.

Anyone know why this happened? The above [self.navigationController setNavigationBarHidden:NO animated:NO] in the viewWillDisappear does not take effect is because of the SecondViewController already popped out? Am I right?

Any suggestions and comments are welcome. Thanks a lot. :)
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I don't know why it doesn't work. Try showing the navbar in viewwillappear of the first view controller.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
So, what happened is when I click this button and back to FirstViewController, the navigation bar does not appear in FirstViewController.

I just put together a quick-and-dirty test project, using your code, and the navBar does appear in the first viewController for me.

P.S. I'd also suggest when calling the superclass' viewWillAppear: or viewWillDisappear: that you do that first before any of your custom code, unless you have a good reason to delay it.
 

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
I don't know why it doesn't work. Try showing the navbar in viewwillappear of the first view controller.

Yup, the navbar does appear in first view controller if I show the bar in the viewWillAppear of the first view controller. Thanks. :)

But, don't know why the previous code can't work... :confused:
 
Last edited:

cthesky

macrumors member
Original poster
Aug 21, 2011
91
0
I just put together a quick-and-dirty test project, using your code, and the navBar does appear in the first viewController for me.

Thanks for your reply. :)

I see, but don't know why the navBar doesn't appear in my app. I tested and retry it so many times but still can't work. I had attached my sample code. If can, can you help me have a look on it ? or if possible, can anyone help me review my sample code to see whether exists any mistake in my code and why the navBar doesn't appear in first view controller after pop out second view controller? Any comments are appreciated. :)

P.S. I'd also suggest when calling the superclass' viewWillAppear: or viewWillDisappear: that you do that first before any of your custom code, unless you have a good reason to delay it.

ok. I had change that to first before any of my custom code.
 

Attachments

  • navigationControllerTest.zip
    86.3 KB · Views: 144
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.