问题
Lets imagine the scenario:
UITabBarController - UITabBar - Tab 1: View Controller A - Tab 2: View Controller B
When I click on View Controller A I want to push another UITabBarController:
UITabBarController -UITabBar - Tab 1: View Controller 1 - Tab 2: View Controller 2 - Tab 3: View Controller 3
Is this possible? To have a UITabBarController push another UITabBarController onto the view stack?
回答1:
You can certainly do this but I would rethink your design. Selecting a UITabBar item and changing the Tab Bar itself goes against Human Interface Guidelines. Besides, in your example, how do you get back to the root view controller?
Perhaps you should use a UITableView that when you tap a cell it pushes a view controller containing a UITabBarController (technically this might go against HIG too since a tab bar should be the same throughout an entire app but I've had plenty of apps adopt this and it seems elegant). So using your example:
RootViewController: pushed as UINavigationController with a UITableView containing two cells: "cell1" & "cell2"
-Tapping on "cell1" pushes a view controller containing UITabBar(I) which contains "View Controller A" and "View Controller B."
-Tapping on "cell2" pushes a view controller containing UITabBar(II) which contains "View Controller 1," "View Controller 2," and "View Controller 3."
In each case, you get a "back" button and the UITabBar itself doesn't have to change.
回答2:
Sure, I just stacked them up in interface builder. There's some frame offsetting issues, but you can see tabbars stacked up. Additionally, the tabbars unstack when other tabs are selected. I also had to make sure the first tab's view was added to the window's view and connected as an IBOutlet
, but otherwise that should do it.
来源:https://stackoverflow.com/questions/6631814/can-i-have-more-than-1-uitabbarcontroller