开发者

Cocoa-Touch: Using UITabBarController with multiple tabs as UINavigationControllers

开发者 https://www.devze.com 2022-12-11 03:26 出处:网络
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 UINavigati

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 defa开发者_开发技巧ult 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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号