现在iOS新建项目工程时,window 默认情况下是以
Main.storyboard
中 initial view controller,
在项目中,如果需要通过代码控制 window 的 rootViewController ,
可以通过如下方法:
1 2 3 4 5 6 7 8
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; RootViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController"]; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; }
|