waterforest
waterforest

Reputation: 144

Navigation bar goes into confusional state

This bug was firstly found in iOS 7, and it can be reproduced in iOS 8 either.

There is a three view controllers A, B and C. Managed by UINavigationController. And I'd like to hide the navigation bar for controller A, not for others.

Here is the code I've written for controller A.

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    self.navigationController.navigationBarHidden = NO;
}

When user comes back via navigation backBarButtonItem, it works fine for me. But when user slides backwards and forward from the left side(That is do not actually go backwards to controller A from controller B, but stay in controller B at last), the navigation bar will go into confusional sate.

Here is a demo to show this issue: [Demo]:https://github.com/heistings/NavigationTest

This problem can be simply fixed by disable the interactivePopGestureRecognizer of navigation controller, but can't say it's perfect:

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

Upvotes: 1

Views: 131

Answers (3)

Ashok Londhe
Ashok Londhe

Reputation: 1491

I got your problem. First Embed navigation controller to ViewController...

  1. Click on storyboard...
  2. Click on View Controller...
  3. Goto Editor section.
  4. Click on Embed in and then click on navigation controller.

And then Write the code below:

 - (void)viewWillAppear:(BOOL)animated {
   [super viewWillAppear:animated];

   [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:animated];
    }

Upvotes: 0

waterforest
waterforest

Reputation: 144

This may be the best way for this issue since we have got the animated from framework:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

Upvotes: 1

ChintaN -Maddy- Ramani
ChintaN -Maddy- Ramani

Reputation: 5164

use animated property to YES.

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

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

Maybe this will help you.

Upvotes: 3

Related Questions