Xib和storyboard对比
- 共同点
- 都用来描述软件界面
- 都用interface builder工具来编辑
- 本质都是转换成代码去创建控件
- 不同点
- xib是轻量级的,用来描述局部UI界面
- Storyboard是重量级的,用来描述整个软件的多个界面,并且能够展示多个界面的跳转关系
加载xib文件
xib文件在编译的后会变成nib文件
第一种加载xib方式
NSArray *xibArray = [[NSBundle mainBundle]loadNibNamed:@"Test" owner:nil options:nil];可以从数组中取出要用的
log:
(">",">",">",">"
)
第二种加载xib方式
UINib *nib = [UINib nibWithNibName:@"Test" bundle:nil];NSArray *xibArray = [nib instantiateWithOwner:nil options:nil];
第三种控制器加载xib方式
- (1)参数传@”View”
XXViewController *vc = [[XXViewController alloc]initWithNibName:@"View" bundle:nil];
XXViewController *vc = [[XXViewController alloc]initWithNibName:nil bundle:nil];
那么加载xib的顺序是下面这样的:
第四种窗口控制器加载xib方式
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
XXController *vc = [[XXController alloc]initWithNibName:NSStringFromClass([XXController class]) bundle:nil];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
关于storyboard
手动创建控制器需要将Xcode加载storyboard去掉
- 关于storyboard创建控制器
第一种:
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
第二种:
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"WAKAKA"];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];