views:

1253

answers:

3

I wanted to start a optimization thread.

I have ran into an interesting situation, I have an iPhone app with 3 UITableViews each displaying more or less the same data (you can say it's a matter of filering). To date I had 3 separate NIBs for this, each with it's own controller, additionaly the UITableViews were inside UINavigationController's 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 (a 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 navControllers 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 UITableView doesn't show, you can only see a UIWindow in it's place. The UITableView stays visible only for the last touched UITabBarItem.

Is there some kind of UITabBar view loading mechanisinm I'm not aware of?

+1  A: 

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.

Brent Royal-Gordon
A: 

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

Kendall Helmstetter Gelner
A: 

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.

silicosaur