在启动时打开SecondViewController insted FirstViewController

时间:2014-02-21 16:44:28

标签: ios redirect uinavigationcontroller uitabbarcontroller

我有一个带有两个导航控制器的TabBarController和一个附加图像。 如果我的应用程序将第一次运行应该打开Second View Controller。

对于导航控制器,我使用下面的代码:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];

    cysViewController *cvc =[sb instantiateViewControllerWithIdentifier:@"cysViewController"];
    questionViewController *qvc = [sb instantiateViewControllerWithIdentifier:@"questionViewController"];
    UINavigationController *nav = (UINavigationController *) self.window.rootViewController;
    nav.viewControllers = [NSArray arrayWithObjects:cvc,qvc, nil];
    [(UINavigationController *)self.window.rootViewController popToViewController:qvc animated:NO];

但是对于tabBarController,我不知道该怎么做。

my controllers

1 个答案:

答案 0 :(得分:0)

您可以通过更改selectedIndex的值来更改所选索引。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions {
   UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
   tabBarController.selectedIndex = 1;
}