UITabBarController-更多按钮不显示 [英] UITabBarController - more button does not show up

查看:33
本文介绍了UITabBarController-更多按钮不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式创建 TabBarController ,因为我希望每个选项卡中的同一Controller显示不同的内容.内容是通过 ID 获取的.我使用情节提要ID的方式与使用 initWithNibName:的方式相同.

I create my TabBarController programatically, because I want the same Controller in every tab displaying different content. The content is fetched by an ID. I use the storyboard id the same way as one would use initWithNibName:.

我在AppDelegate中执行此操作:

I do this in the AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];

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

    for (int i = 0; i < 7; i++) {
        MyViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"MyView"];
        [svc setID: i];
        [tabBarController addChildViewController:svc];
    }

    [self.window makeKeyAndVisible];
    [self.window setRootViewController: tabBarController];

    return YES;
}

但是TabBar仅显示7个选项卡中的5个.很好,因为一次只能显示5个标签.不幸的是...更多按钮不可见.因此无法访问最后两个标签.

But the TabBar shows only 5 of the 7 Tabs. This is fine, because only 5 tabs can be visible the same time. Unfortunately the ... More button is not visible. So the last 2 tabs are not accessible.

有人知道如何强制显示更多"按钮,或者为什么不显示该按钮?

Does anyone have an idea how to force the More button to show up, or why it does not show up?

致谢!

推荐答案

它没有显示出来,因为您正在使用 UIViewController 的addChildViewController 方法将视图控制器添加到选项卡栏控制器中.code>方法,而不是选项卡栏控制器方法.因此,我认为正在发生的事情是标签栏控制器并不真正知道它具有超过5个视图控制器.

It's not showing up because you are adding viewcontrollers to the tab bar controller using addChildViewController method which is a UIViewController method and not a tab bar controller method. So i think what's happening is the tab bar controller doesn't really know that it has more than 5 view controllers.

如果要显示更多视图控制器,请直接设置选项卡栏控制器的viewControllers数组.修改您的代码,如下所示:

If you want the more view controller to show up, set the viewControllers array of the tab bar controller directly. Modify your code to something like below:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];  
NSMutableArray *vcArray = [NSMutableArray array]; 
for (int i = 0; i < 7; i++) {
    ViewController *svc = [storyboard instantiateViewControllerWithIdentifier:@"MyView"];
    [svc setID: i];
    [vcArray addObject:svc];
}
[tabBarController setViewControllers:vcArray]; //This is the important part.
[self.window setRootViewController: tabBarController];
[self.window makeKeyAndVisible];

这篇关于UITabBarController-更多按钮不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆