Reputation: 3607
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.
Upvotes: 7
Views: 6105
Reputation: 4606
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];
Upvotes: 1
Reputation: 69027
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
.
Upvotes: 11
Reputation: 17317
Do you have a UINavigationController? You don't refer to one. If you aren't using a UINavigationController then it is likely that your UITabBarController isn't getting set up properly as the topViewController.
Upvotes: 0