控制器常見的建立方式有如下幾種:
spa
1> 經過storyboard建立.
code
2> 直接建立:it
JNViewController *JN = [[JNViewController alloc] init];
3> 指定xib文件來建立:
class
JNViewController *JN = [[JNViewController alloc] initWithNibName:@"JNViewController" bundle:nil];
下面詳細介紹如何經過storyboard建立控制器;方法
1.先加載storyboard文件(Main是storyboard的文件名);
im
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
2.接着初始化storyboard中得控制器(兩種方法):
img
1> 初始化"初始控制器"(箭頭所指的控制器)
文件
JNViewController *JN = [storyboard instantiateInitialViewController];
2> 經過一個'標識'初始化對應的控制器
view
JNViewController *JN = [storyboard instantiateViewControllerWithIdentifier:@」JN"];