Help. Navigation bar does not appear after pop the view controller.

Discussion in 'iOS Programming' started by cthesky, Nov 21, 2012.

  1. cthesky macrumors member

    Aug 21, 2011
    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:

    - (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. :)
  2. PhoneyDeveloper macrumors 68040


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


    Staff Member

    Sep 2, 2004
    The Centennial State
    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.
  4. cthesky, Nov 21, 2012
    Last edited: Nov 21, 2012

    cthesky thread starter macrumors member

    Aug 21, 2011
    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:
  5. cthesky thread starter macrumors member

    Aug 21, 2011
    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. :)

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

    Attached Files:

Share This Page