To hide my tab bar I do
- (void)viewDidLoad
{
[super viewDidLoad];
self.tabBarController.tabBar.hidden=YES;
}
So clearly to make it show again, all I need to do is call
self.tabBarController.tabBar.hidden=NO;
But in which lifecycle method should I make this call? There seems to be disagreement on which lifecycle methods are still valid in the latest iOS/Xcode. Also, as a matter of sound engineering, I would like to know the very correct answer: viewDidDisappear
or ViewDidUnload
or ViewDidDispose
?
To Answer your question from apple doc
viewDidUnload [...] Deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.
So viewDidUnload
is deprecated in iOS 6.0 and the best place to put self.tabBarController.tabBar.hidden=NO;
is in viewDidDisappear
but as viewDidDisappear
call when view removed from screen not from memory it can be any case.So if view appear again it will not call viewDidLoad
so in this case tabbar
will remain unhidden and to solve that you need to do two things.
Put self.tabBarController.tabBar.hidden=YES;
in viewWillAppear
instead of viewWillLoad
and
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden=YES;
}
and put unhidden call of tabbar to viewDidDisappear
- (void)viewWillDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
self.tabBarController.tabBar.hidden=NO;
}
It will manage all cases and other places are not safe to put this call.You should always work with viewWill/DidAppear
and viewDid/WillDisappear
and also viewWillLoad
in some cases as they are safe and always call if there is not an uncertain condition(crash etc).