Reputation: 2209
I have ran into an interesting situation, I have an iPhone app with 3 UITableViewController
s each displaying more or less the same data (you can say it's a matter of filtering). To date I had 3 separate NIBs for this, each with it's own controller, additionally the UITableViewController
s were inside UINavigationController
for the sake of buttons on top.
Now to optimize the app and reduce it's footprint, I pack all the logic to one common controller (an UITableViewController
) and left only one NIB in place. The common controller would take care of filtering the data out, and pointing to the correct data.
So, I load the same common controller to 3 of the navigation controllers:
navControllerA = [[UINavigationController alloc] initWithRootViewController: commonTableController];
and added these navigation controllers to the UITabBarController
:
navigationControllersArray = [NSArray arrayWithObjects: navControllerA, navControllerB, navControllerC, nil];
[tabController setViewControllers:[NSArray arrayWithArray:navigationControllersArray]];
Now all is fine, the tabs display, the table views show up. But once you touch the next UITabBarItem
and go back to the previous one the UITableViewController
doesn't show, you can only see a UIWindow
in it's place. The UITableViewController
stays visible only for the last touched UITabBarItem
.
Is there some kind of UITabBar
view loading mechanism I'm not aware of?
Upvotes: 0
Views: 1973
Reputation: 75058
If you really want to toggle data sets within one view, it seems like a better approach would be to use a toolbar rather than a tab bar. The tab bar is all about switching views where as the other poster noted, all views have to be children of one view and one navigation controller. Having a tab bar that calls into this single controller to switch data sets make much more sense, or else using a UISegmentedControl would also work well (since you have three elements and you can only have up to three segments).
Upvotes: 0
Reputation: 17861
Each view controller can only be on one navigation controller's stack, and it cannot be in several places on that stack.
If you really want to save memory by only using one view controller, I would suggest that instead of using a tab bar controller, you just use a tab bar view and set your root view controller as its delegate. The root view controller would then directly interpret tab bar events and change its filtering accordingly.
Upvotes: 1