IOS 模仿有storyboard的项目控制器的创建

 

● 先加载storyboard文件(Test是storyboard的文件名)

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil];

● 接着初始化storyboard中的控制器

➢ 初始化“初始控制器”(箭头所指的控制器)

NJViewController *nj = [storyboard instantiateInitialViewController];

➢ 通过一个标识初始化对应的控制器

NJViewController *nj = [storyboard instantiateViewControllerWithIdentifier:@”nj"];

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   
    // Override point for customization after application launch.
    // 1.创建winodw
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    // 2.创建控制器
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    NJViewController * vc = [storyboard instantiateInitialViewController];
    // 3.设置window的根控制器
    self.window.rootViewController = vc;
    // 4.显示window
    [self.window makeKeyAndVisible];
    
    return YES;
}

 

posted on 2017-03-08 16:33  守望星空  阅读(97)  评论(0编辑  收藏  举报

导航