一、系統調用
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
- File.s Owner 的 Class 設置為自定義控制器類型
- 延遲加載
loadNibNamed
- File.s Owner 的 Class 的類為NSOjbect
- 即時加載
UINib
// 獲取UINib對象
UINib* nib = [UINib nibWithNibName:@"AppCell"bundle:nil];
// 取出cell對象Owner 多視圖控制器使用
AppCell *cell = [nib instantiateWithOwner:nil options:nil].lastObject;