views:

121

answers:

2

I'm building an app that has 5ish tabs, each of them will have table + item details views.

So I have to create a UITabBarController and the items instead of being the direct views are the UINavigationControllers with a default view inside.

I've done this, and it works, but..

Isn't this a waste? Looking at what the UITabBarController does is just create a navigation controller and a set of buttons in the tab bar that pushes and pops it's items.

Is it possible to use the UITabBarController's navigation controller somehow instead of creating the 5 new ones?

+1  A: 

The UITabBarController represents its sub-tabs as an array of UIViewControllers not an array of UINavigationControllers. Therefore your approach is exactly right: use UINavigationControllers (subclass of UIViewController) in place of standard view controllers when you want to achieve navigation within a given tab.

awolf
I agree with what you just said, but the `UITabBarController` still does the view switching, which is exactly what the `UINavigationController` does when pushing views with `animated:NO`, so I suspect it might have a navigation controller behind the scenes.
Prody
You are right that UITabBarControllers and UINavigationControllers both do the view switching. This "managing views" concept is inherited from their common superclass UIViewController. You should think of UINavigationController and UITabBarController as siblings. I believe they are not dependent on each other to exist and that they each manage their subviews in different ways.
awolf
+1  A: 

No, it is not wasteful. Each tab is a separate stack of views, which is why you need different navigation controllers - a navigation controller can have only one root object, not four or five.

When you switch tabs, it goes back to where you had navigated to - and when you press a tab twice it tells the navigation controller to jump to the top of the stack. If you used only one navigation controller across all tabs, this would break - as would tab specific customization of the nav bars.

It's not like a navigation controller even has a view of its own. It's just the space taken by a view controller object, which is not much at all...

Kendall Helmstetter Gelner