开发者

How to nest UITabBarController

I am trying to nest a UITabBar inside another one, like so:

UITabBarController *tabController = [[UITabBarController alloc] init];
tabController.delegate = self;

UITabBarController *friendsTabController = [[UITabBarController alloc] init];

FindFriendsViewController *findFriendsController = [[FindFriendsViewController alloc] initWithNibName:@开发者_StackOverflow社区"FindFriendsViewController" bundle:nil];
findFriendsController.rootViewController = self;
UINavigationController *findFriendsNavController = [[UINavigationController alloc] initWithRootViewController:findFriendsController];
findFriendsNavController.tabBarItem.title = NSLocalizedString(@"Add", nil);

friendsTabController.viewControllers = [NSArray arrayWithObjects:friendStreamController, friendListController, findFriendsNavController, nil];

tabController.viewControllers = [NSArray arrayWithObjects:nearbyNavController, friendsTabController, meController, checkInController, logController, nil];

(obviously, some of the code, such as the other tabs is ommitted for brevity)

When I do this, and click on the "Friends" tab of the outer tab bar, the inner tab bar appears directly above the outer one. I don't want this. I would like the inner tab bar to take the place (at the bottom of the window) of the outer one when it is selected.

I've tried doing this by hiding the outer tab bar, by setting it to hidden in the UITabBarController delegate method, and I've tried setting the frame of the inner tab bar to manually position it at the bottom of the screen like so:

friendsTabController.tabBar.frame = CGRectMake(0, 430, 320, 50);

When I hide the outer tab bar the inner one still appears the same distance from the bottom edge of the screen, and the outer one is replaced by a blank rectangle.

When I try setting the frame of the inner tab bar, the only part of it that is visible is any part that would be outside the frame of the outer tab bar.

I've tried googling this to no avail. Surely this kind of navigation is not so rare? Before attempting this I had assumed it would be supported in the SDK.

Any ideas?

TIA,

Tom


You could try having a single tab-bar controller in your app. When a user clicks on a tab that leads to a new set of tabs, replace all of the tabs in the single-tab-bar controller. I'm not sure you navigate "back" to the top level, but I presume you have something in mind.

I dont think this is great UI, but you can probably make it work this way.


I think a better solution to your problem would be to add a containerView to the viewController in the tab that you would like to nest the second tabBarController. Then you can add childViewControllers to that containerView and create a custom segue to those childViewControllers in much the same way a tabBarController does. This gives you the option to put your new custom "tab bar" ( I recommend a segmentedControl ) anywhere you like in the viewController containing the containerView. I think it's a more acceptable way to handle a nested tabBarController. Also the user will not be confused with a tabBar suddenly changing appearance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜