learner learner - 1 year ago 90
Objective-C Question

lifecycle: when do I hide and show tab bar in UIViewController

To hide my tab bar I do

- (void)viewDidLoad
[super viewDidLoad];

So clearly to make it show again, all I need to do is call


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:

Answer Source

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];

and put unhidden call of tabbar to viewDidDisappear

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

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download