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];

    

posted on 2017-04-25 14:32  ming1025  阅读(141)  评论(0编辑  收藏  举报