用故事板视图控制器创build一个编程选项卡?

我有一个标签栏是以编程方式创build的,我很难初始化与视图相关的故事板。

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

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

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

- (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]]; } 

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

 // 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"];