I am trying to make an app with two different tab bar controllers, one for a pre-logged in state, and one for an post-logged in state. My current strategy is to create all the views, add them to two arrays (one for each tabBarController) and then switch the tabBarController assigned as the subview with some logic.
I am currently having problems with the views that are common between the two tabBarControllers. If I only make one tabBarController from one Array, everything works great. But when I try to make a second array with the same views in the first array, all of the common views no longer appear in the tabBarController with views from the original array.
First I’m not sure if this is even the correct approach to my problem. Second I am not sure why pointers in one array seem to lose their references when adding the pointers to another array.
Here is my code:
NSArray *loggedViewControllers = [NSArray arrayWithObjects:squareView, circleView, starView, diamondView, nil];
loggedTabBarController.viewControllers = loggedViewControllers;
NSArray *notLoggedViewControllers = [NSArray arrayWithObjects:squareView, circleView, diamondView, nil];
notLoggedTabBarController.viewControllers = notLoggedViewControllers;
[release squareView];
[release circleView];
[release diamondView];
[release starView];
[self.window addSubview:[loggedTabBarController view]];
[self.window makeKeyAndVisible];
From if I run this code I will get a tab bar with blank, starView, blank blank.
If I run the following:
[self.window addSubview:[notLoggedTabBarController view]];
Everything appears fine.
Thank for help.
I don’t this approach is going to work.
When you add a view as a subview to another view, it first removes that view from the superview it is currently in (if it is in one).
Since the TabView managed by the TabBarController is a subclass of UIView it will behave the same way – so when you add the view to the TabBarControllers view list, and it thus subsequently adds that view as a subview to its TabBarView, it will also be removing that view from the other TabBarControllers TabView.
You would be better off looking at the delegate methods of TabViewController I think, and just manage one single list in one TabViewController.