0

我有一个旧项目,它的视图实现为 xibs。视图是带有标签栏的控制器。

现在我想添加一个新的 UITabBarItem,但我希望这个新项目不是基于 xib,而是基于 Storyboard。意思是,我想只为这个标签栏项目的内容使用故事板,而让应用程序的其余部分保持原样。

我做了以下事情:

  • 创建了新的故事板
  • 创建了一个新的 ViewController,它应该是故事板的包装器
  • 然后我将 Tab 的 IB 中的底层 VC 更改为新的 VC

但是我现在该如何进行呢?我尝试这样做以使 InitialViewController 成为选项卡的 ViewCONtroller:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
{
    UIStoryboard *financeStoryboard = [UIStoryboard storyboardWithName:@"WS_Finanzierung_Storyboard_iPhone" bundle:nil];
    UIViewController * initialViewController = [financeStoryboard instantiateInitialViewController];

    [self presentViewController:initialViewController animated:YES completion:nil];
}
return self;
}

但它不起作用(崩溃了..)。

问:无论如何,这是正确的做法吗?有这样做的最佳做法吗?

提前致谢

4

1 回答 1

3

试试这个。。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    UIViewController *viewController3 = [[StoryViewController alloc] init];
    UIStoryboard *tableViewStoryboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    viewController3 = [tableViewStoryboard instantiateViewControllerWithIdentifier:@"newTab"];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

像这样分配故事板标识符--> 在此处输入图像描述

取消选中是初始视图控制器 --> 在此处输入图像描述

输出会是这样的..

在此处输入图像描述在此处输入图像描述

于 2013-08-28T13:30:03.487 回答