Programmatically set rootViewcontroller for UINavigationcontroller in Storyboard in Appdelegate

前端 未结 2 1167
夕颜
夕颜 2020-12-31 11:06

I have a value in NSUserdefaults. I am using storyboard, it is embedded in UINavigationController.

- (BOOL)application         


        
2条回答
  •  借酒劲吻你
    2020-12-31 11:43

    You can create an object of UINavigationController with your ViewController as per if/else condition and set the navigation controller as rootViewController property of window in AppDelegate as follows:

    LoginViewController *loginController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"loginController"]; //or the homeController
    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:loginController];
    self.window.rootViewController = navController;
    

提交回复
热议问题