1.
PS :犯了个错误,在使用instantiateInitialViewController时,得到的类控制器为空。。。。
即用下面的方法加载 policySB 不为空,但是 policy 为nil。
UIStoryboard *policySB = [UIStoryboard storyboardWithName:@"policySB" bundle:nil];
PolicyController * policy = policySB.instantiateInitialViewController;
导航控制器弹出policy(nil) 不崩溃,也没有任何反应。。。。
2.加载顺序
- (void)loadView
{
[super loadView];
UIView *v4 = [[UIViewalloc] initWithFrame:CGRectMake(200,200, 50, 50)];
v4.backgroundColor = [UIColoryellowColor];
[self.viewaddSubview:v4];
NSLog(@"%s",__FUNCTION__);
}
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"%s",__FUNCTION__);
UIView *v3 = [[UIViewalloc] initWithFrame:CGRectMake(150,150, 50, 50)];
v3.backgroundColor = [UIColorblueColor];
[self.viewaddSubview:v3];
[super viewWillAppear:animated];
}
- (void)viewDidLoad
{
[superviewDidLoad];
UIView *v2 = [[UIViewalloc] initWithFrame:CGRectMake(100,100, 50, 50)];
v2.backgroundColor = [UIColorredColor];
[self.viewaddSubview:v2];
NSLog(@"%s",__FUNCTION__);
}
- (void)awakeFromNib
{
UIView *v1 = [[UIViewalloc] initWithFrame:CGRectMake(50,50, 50, 50)];
v1.backgroundColor = [UIColorgreenColor];
[self.viewaddSubview:v1];
[superawakeFromNib];
NSLog(@"%s",__FUNCTION__);
}
每个storyboard 对应一个类:
通过调试证明从storyboard 中加载的并获取 instantiateInitialViewController (在命名上:storyboard的class 为对应的类名)建立连接
打印结果:
2015-11-17 20:45:52.759 Storyboard使用技巧[23078:1965696] -[HMTableViewController loadView]
2015-11-17 20:45:57.603 Storyboard使用技巧[23078:1965696] -[HMTableViewController viewDidLoad]
2015-11-17 20:46:00.030 Storyboard使用技巧[23078:1965696] -[HMTableViewController viewDidLoad]
2015-11-17 20:46:07.646 Storyboard使用技巧[23078:1965696] -[HMTableViewController awakeFromNib]
2015-11-17 20:46:21.162 Storyboard使用技巧[23078:1965696] -[HMTableViewController viewWillAppear:]
加载顺序:loadView -->viewDidLoad --> awakeFromNib --> viewWillAppear
加载出四个不同颜色的View