Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewDidUnload ,viewWillDisappear not called in tabBarContoller

I am making a view based application in which the first controller is viewcontroller there is login screen ,after login the next view is tabbar controller and I have 2 tabbar items on that tabbar . Until this everything works fine . Now when i switch between these two views the viewWillDisappear, viewDidUnload is not called of previous tab clicked .

P.S.Even the viewwillAppear was not called ,which i called it with the Default Notification. Don't know what the issues are. Hope I am clear with my question.

like image 576
mrugen munshi Avatar asked Jul 04 '11 08:07

mrugen munshi


2 Answers

First of all, when switching view in a UITabBarController, the viewDidUnload function is not called because the view is not actually unloaded. So, this is normal.

What should work out of the box is viewWillAppear/viewDidDisappear. But there is a catch. Depending on how you show your views, it might be that viewWillAppear/viewDidDisappear are not called by the framework for you. For example, this happens if you add your view as a subview, but there are more cases. I don't know how you display your tab bar, so cannot say anything more specific about it.

The easy solution I suggest to fix this is overriding the tabBarController:didSelectViewController: selector in you tab bar controller delegate. From there you could implement you own logic or call viewDidDisappear.

like image 110
sergio Avatar answered Oct 14 '22 08:10

sergio


You should put your TabBar controller in MainWindow.xib.

First when you show loginscreen you will add your RootViewController like this:

[self.window addSubview:self.rootview.view];

And when login is complete you can remove your RootViewController from mainwindow and add TabBarController in the mainwindow like this:

    [self.rootview.view removeFromSuperview];
    [self.window addSubview:self.tabBarController.view];
like image 37
Rakesh Bhatt Avatar answered Oct 14 '22 08:10

Rakesh Bhatt