Reputation: 3541
I seem to not yet have a sufficient understanding of UITabBar, UITabBarController, and Navigation Controller to do what I'm wanting to do. I'm hoping someone can provide some guidance.
I have a total 8 VCs. I would like five of these to be selectable from a TabBar on the first (startup) screen, and selection of any item would load a particular VC. Once a VC has been selected, it will load, and I need to have a DIFFERENT set of about 5 of the 8 total options as potential destinations. Same thing for any of the others.
So, a given VC would need its own TabBar and could have ANY of the 8 VCs on it. Essentially, I want users to be able to switch from one VC to the next with a tab bar, without having to go back to the root VC.
I'm kind of clear on how to use the tabbarcontroller on startup screen to load the views I first want. But given the VC that is loaded may need a different selection of possible VCs in ITS tab bar, how does one set this up?
TO recap, I have
ROOT VC HAS THE FOLLOWING CHOICES
VC-A
VC-B
VC-C
VC-D
VC-D
IF YOU SELECT VC-A, YOU'LL HAVE THE FOLLOWING CHOICES FROM VC-A
VC-C
VC-D
VC-E
VC-F
IF YOU SELECT VC-B YOU'LL HAVE THE FOLLOWING CHOICES FROM VC-B
VC-A
VC-C
VC-D
VC-E
VC-R
AND SO ON.
I'd like all these choices to based from the UITabBar or UITabBarController. Since each VC can require a lot of memory, I'm also concerned that if, for example, VC-B chooses VC-D, that I can destroy VC-B (or at least portions of its implementation, to be reloaded as necessary) to conserve memory (reinstantiating as needed).
It is late. I hope I've explained adequitely what I'm trying to do. Also, not using any NIBs; everything is coded programmically.
Thanks in advance for any help anyone can provide. I'm open to any & all suggestions.
Upvotes: 1
Views: 147
Reputation: 6747
I think the best approach would be to use a single UITabBarController
. Initialize it with your first 5 VCs and set its delegate. Your UITabBarControllerDelegate
should implement tabBarController:didSelectViewController:
. Inside that delegate method refresh the VCs in your UITabBarController
according to which VC was selected, so that only the VCs relevant to the selected VC are shown.
On the other hand, I'd strongly advise against it. Such a navigation structure seems to be very very complex for the user. Maybe you could make a better app by simplifying your structure.
Upvotes: 2
Reputation: 13020
Try this
UITabBarController *tabBar = [[UITabBarController alloc]init];
UINavigationController* nav1=[[UINavigationController alloc]init];
UINavigationController* nav2=[[UINavigationController alloc]init];
UINavigationController* nav3=[[UINavigationController alloc]init];
FirstVC *ObjFirstVC = [[FirstVC alloc] init];
nav1.viewControllers=[NSArray arrayWithObjects:ObjFirstVC, nil];
nav1.tabBarItem.title=@"First";
SecondVC *ObjSecondVC = [[SecondVC alloc] init];
nav2.viewControllers=[NSArray arrayWithObjects:ObjSecondVC, nil];
nav2.tabBarItem.title=@"Second";
ThirdVC *ObjThirdVC = [[ThirdVC alloc] init];
nav3.viewControllers=[NSArray arrayWithObjects:ObjThirdVC, nil];
nav3.tabBarItem.title=@"Third";
tabBar.viewControllers=[NSArray arrayWithObjects:nav1,nav2,nav3,nil];
Upvotes: 2
Reputation: 10175
What you need is a UITabBarController
for each tab set a UINavigationController
(you can do this every easy in storyboard) as the root, for each UINavigationController
set a root view controller (the first view controller that you want to display when the user taps for the first time on that tab).
After you complete the above suggestion, you will have 5 tab bars with 5 UINavigationControlles
with root view controllers, now you can define whatever navigation you like for each tab (push/pop).
Upvotes: 1