I have this problem: i have a view controller (embedded in a navigation controller) that after doing an action triggers a manual segue pushing a new view controller, however in the new view controller there is no navigation bar because in the first controller i had implemented the viewWillDisappear method like this:
- (void)viewWillDisappear:(BOOL)animated {
// Hide the navigation bar just before the view disappear
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
Here is the code for the manual segue that's inside an IBAction:
[self performSegueWithIdentifier:@"tutorialSegue" sender:self];
I'd tried like this
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self navigationController] setNavigationBarHidden:NO animated:NO];
}
but it doesn't work, actually in the debugger i noticed navigationcontroller is equal to nil and i just can't figured out why.
If you want StartViewController to hide navigation bar, and DestinationViewController to show it:
Add corresponding code to -(void)viewWillAppear:
method.
StartViewController:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
DestinationViewController:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
If you want both view controllers to have navigation bar, just remove all lines that contain setNavigationBarHidden:
You problem here is that your viewDidLoad
is being called before your viewWillDisappear
. You must load a new view before you can unload the parent (visually). So you are setting the nav bar visible and hiding it again.
Navigation bars are universal between the views nested inside of it. There really should be no reason to hide it when a view is disappearing unless the childview view does not need it. If you further explained what you are attempting to do we can help more. But in the mean time if you just remove your viewWillDisappear
implementation (at least what you are showing us) you should be good. Otherwise you can set the hidden property to no
in your DestinationViewController's viewWillAppear
or viewDidAppear
(depending on the calling order).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With