控制器

来源:互联网 发布:软件 新技术 编辑:程序博客网 时间:2024/04/27 17:50

如何创建一个控制器

1 通过storyboard创建

加载storyboard

UIStoryboard *storyboard =[UIStoryboard storyboardWithName:@"name" bundle:nil];

创建storyboard 里面的控制器

UIViewController *vc=[storyboard instantiateInitialViewController];

self.window.rootViewController =vc;


Storyboard中有个属性叫 storyboardID  利用storyboardID可以加载控制器

UIViewController *vc=[storyboard instantiateViewControllerWithIdentifier:@"storyboardID "];

self.window.rootViewController =vc;

2 直接创建

ViewController  *dxt=[[ViewController alloc] init];

3制定xib文件来创建

ViewController *dxt=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];


将Storyboard设置为mainstoryboard        AppeDelegate会自动做三件事

1 创建window

self.window=[[UIWindow alloc] initWithFram:[UIScreen mainScreen].bounds]; 

2加载storyboard,并且创建初始化控制器(箭头所指的控制器)

UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];

self.window.rootViewController=[storyboard instantiateInitialViewController];

3显示窗口

[self.window makeKeyVisible];

0 0
原创粉丝点击