iOS 一一 根据storyBoard加载window根控制器的View


1.加载指定的storyBoard

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

2.加载箭头所指向的控制器.

UIViewController *vc = [storyBoard instantiateInitialViewController];

3.加载指定标识的控制器.

UIViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"VCStoryBoardID"];

iOS 一一 根据storyBoard加载window根控制器的View_第1张图片



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 通过storyBoard加载控制器(通过storyBoard来加载Window根控制器的view)
    
    //1. 创建窗口
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    
    //2. 设置窗口的根控制器
    //2.1创建storyBoard对象
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    //2.2 加载storyBoard箭头指向的控制器
//    UIViewController *vc = [storyBoard instantiateInitialViewController];
    //2.3 加载storyBoard中指定的控制器
    UIViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"ZY"];
    self.window.rootViewController = vc;
    
    //3. 显示窗口
    [self.window makeKeyAndVisible];
    
    
    return YES;
}



你可能感兴趣的:(iOS)