iOS大神班笔记04-View的加载
iOS开发中一个控制器创建View的过程(注意标注的地方):
1.通过storyboard加载
UIStoryboard的三个方法:
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(nullable NSBundle *)storyboardBundleOrNil; - (nullable __kindof UIViewController *)instantiateInitialViewController; - (__kindof UIViewController *)instantiateViewControllerWithIdentifier:(NSString *)identifier;
实例如下:
// name:storyboard名称不需要后缀
UIStoryboard *stroyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// 加载sotryboard描述的控制器
// 加载箭头指向的控制器
UIViewController *vc = [stroyboard instantiateInitialViewController];
UIViewController *vc = [stroyboard instantiateViewControllerWithIdentifier:@"blue"];
2.通过xib加载
// 通过xib创建控制器
ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
如果我的内容能对你有所帮助,我就很开心啦!
浙公网安备 33010602011771号