UIViewController的创建方式

UIViewController 的创建方式分为三种

    

//    第一种创建方式 直接创建

//    ZYWViewController *vc = [[ZYWViewController alloc] init];

//    vc.view.backgroundColor = [UIColor blueColor];

    

//    第二种创建方式 通过 storyboard 创建

//    UIStoryboard *testBodard = [UIStoryboard storyboardWithName:@"Test" bundle:[NSBundle mainBundle]];

    // 获得 初始化视图控制器(即箭头指示的控制器)

//    ZYWViewController *vc = [testBodard instantiateInitialViewController];

    // 根据identifier 获取控制器(即 storyboard ID 设为 test

//    ZYWViewController *vc = [testBodard instantiateViewControllerWithIdentifier:@"test"];

    

//    第三种创建方式 通过 xib 创建

    // 注意两点 首先设置xib的first owner 的class当前controller

    //         然后设置first owner的view为你拖的view(连线)

    ZYWViewController *vc = [[ZYWViewController alloc] initWithNibName:@"test" bundle:nil];

posted @ 2014-12-21 19:55  杯水文圣  阅读(289)  评论(0编辑  收藏  举报