使用故事板视图控制器创建程序化选项卡栏? [英] Creating a programmatic tab bar with storyboard view controllers?

查看:120
本文介绍了使用故事板视图控制器创建程序化选项卡栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以编程方式创建的标签栏,我在初始化与视图关联的故事板时遇到了困难。

I have a tab bar that is created programmatically and I'm having difficulties initializing a storyboard associated with a view.

我能够成功加载视图在没有故事板的标签栏中(参见下面的代码),但视图只是部分显示,因为一些UI组件在故事板中。

I'm able to load the view successfully in the tab bar without the storyboard (see code below) but the view is only partially showing because some of the UI components are in the storyboard.

我的故事板的名称是MainStoryboard,我将故事板视图标识符设置为SettingsViewController。

The name of my storyboard is MainStoryboard and I set the storyboard view identifier to SettingsViewController.

如何在下面的代码中初始化SettingsViewController的故事板?

How can I initialize my storyboard for SettingsViewController in the code below?

- (void)createTabBarItems {
    tabBarController = [[UITabBarController alloc] init];

    settingsViewController  = [[SettingsViewController alloc] init];


    UINavigationController *sett = [[[UINavigationController alloc]
                                     initWithRootViewController: settingsViewController] autorelease];

    [sett.tabBarItem setTitle:@"Settings"];
    [sett.tabBarItem setImage:[UIImage imageNamed:@"settings.png"]];

    [tabBarController setViewControllers:
        [NSArray arrayWithObjects:sett, sett, sett, sett, nil]]; 
}


推荐答案

如果你想初始化在故事板中查看控制器,您必须使用故事板方法而不是直接分配视图控制器:

If you want to initialize the view controller as in the storyboard you have to use the storyboard methods instead of allocating the view controller directly:

// load the storyboard by name
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

// either one of the two, depending on if your view controller is the initial one
settingsViewController = [storyboard instantiateInitialViewController];
settingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"SettingsViewController"];

这篇关于使用故事板视图控制器创建程序化选项卡栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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