简体   繁体   中英

How to add 9 or more tab to UITabBarController?

It seems UITabBarController limit the amount of tab to 8 when using vertical tab in iPad.
But I want to show 9 or more tab.

At first, I set only 1~7th tab to UITabBarController,
and use 8th and 9th tab outside of UITabBarController as following source code.
It shows 9 tab, but causes some problem such as broken toolbar, rotating withoug permission or so..

Is there any way to show 9 or more tab correctly?

#define RT_TABMEMU_ITEM_MAX 8
#define RT_TABMEMU_ITEM_MAX_WITH_MORE 7

- (void)setSelectedViewController:(UIViewController *)selectedViewController {
    ...

// If the amount of viewController is less than 9, 
// or index of selectedViewController is 0~6, 
// set selectedViewController to UITabBarController
    if (!(RT_TABMEMU_ITEM_MAX < [self.viewControllers count]
          && RT_TABMEMU_ITEM_MAX_WITH_MORE <= [self.viewControllers indexOfObject:selectedViewController])) {
        [super setSelectedViewController:selectedViewController];
    }

    ...
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UIViewController *selectedController = (self.viewControllers)[indexPath.row];

    if (self.selectedViewController != selectedController) {
        [self setSelectedViewController:selectedController];

    ...

I suggest you try out the InfiniTabBar for iOS open source project. With it you can add as many tabs as you like. I have used it in a project of my own and it is quite good!

All the best!

It is released under PUBLIC LICENCE or as the author says of the licence:

As always, all my source code can be used royalty-free into your app. Just make sure that you don't remove the copyright notice from the source code if you make your app open source. You don't have to attribute me in your app, although I would be glad if you do so.

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