2-init 方法总结

2016-11-02  本文已影响9人  千秋画雪

一、系统调用

1.纯代码系统调用

initWithFrame

2. 使用 Storyboard 和 Xib 加载时系统调用

initWithCoder 从文件实例化时调用
awakeFromNib 设置控件 可以保证所有的连线等操作生效,不需要调用super

二、手动调用

1. 加载 storyboard

// 实例化 UIStoryboard 对象
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"KMHTableViewController" bundle:nil];
// 从 storyboard 中实例化控制器
UIViewController *VC = [storyboard instantiateViewControllerWithIdentifier:@"ID"];

2. 加载 xib

initWithNibName

loadNibNamed

UINib

// 获取UINib对象
UINib* nib = [UINib nibWithNibName:@"AppCell"bundle:nil];
// 取出cell对象Owner 多视图控制器使用
AppCell *cell = [nib instantiateWithOwner:nil options:nil].lastObject;
上一篇 下一篇

猜你喜欢

热点阅读