在App Delegate中获取对Embed tabBarController的访问权限

时间:2014-06-26 06:59:27

标签: ios storyboard

我遇到一个问题,我可以访问嵌入tabbarcontroller并将其设置为index2

我尝试过以下代码,但它不会工作,只会转到第一个索引:

UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"MainFunction" bundle:nil];
  MyViewController   *theInitialViewController = [secondStoryBoard instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = theInitialViewController;
    [self.window.rootViewController.tabBarController setSelectedIndex:2];/        [self.window.rootViewController.navigationController.tabBarController setSelectedIndex:2];
    [self.window makeKeyAndVisible];

enter image description here

使用上面的代码无法更改为第二个标签。

有人能给我一些建议吗? 非常感谢你。

1 个答案:

答案 0 :(得分:0)

从故事板获取的viewController是一个标签栏控制器。

  UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"MainFunction" bundle:nil];
  UITabBarViewController *theInitialViewController = [secondStoryBoard instantiateInitialViewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = theInitialViewController;
    [theInitialViewController setSelectedIndex:2];
    [self.window makeKeyAndVisible];