创建控制器的几种方式

控制器常见的创建方式有以下几种
通过storyboard创建
1、
直接创建
MJViewController *mj = [[MJViewController alloc] init];

2、
指定xib文件来创建
MJViewController *mj = [[MJViewController alloc] initWithNibName:@"MJViewController" bundle:nil];

3、
先加载storyboard文件(Test是storyboard的文件名)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil];

接着初始化storyboard中的控制器
初始化“初始控制器”(箭头所指的控制器)
MJViewController *mj = [storyboard instantiateInitialViewController];

通过一个标识初始化对应的控制器
MJViewController *mj = [storyboard instantiateViewControllerWithIdentifier:@”mj"];

猜你喜欢

转载自invictus-fang.iteye.com/blog/2151962