简体   繁体   中英

Cocoa-Touch: Using UITabBarController with multiple tabs as UINavigationControllers

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 UINavigationController s 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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM