Question

I have ran into an interesting situation, I have an iPhone app with 3 UITableViewControllers 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 UITableViewControllers 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 UITabBarview loading mechanism I'm not aware of?

Was it helpful?

Solution

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.

OTHER TIPS

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).

Using UITabbarController inside UINavigationController is not supported. You can write a normal UIViewController to mimic the UITabbbarController, that can be pushed to view stack. See this SO question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top