我正在尝试做这样的事情 -
- (void)viewDidLoad {
[super viewDidLoad];
ThingViewController *thingViewController = [self thingControllerForCard:self.card];
thingViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
UIView *view = [thingViewController view];
[self.view addSubview:view];
}
它只是给我一个白色屏幕,里面没有任何东西。如果我在导航堆栈上按下新的视图控制器,它会正确显示控制器。知道我可能会缺少什么吗?
答案 0 :(得分:2)
您应该在viewDidLayoutSubviews
上设置thingViewController框架。
viewDidLoad
目前没有正确设置框架:
- (void)viewDidLoad {
[super viewDidLoad];
ThingViewController *thingViewController = [self thingControllerForCard:self.card];
UIView *view = [thingViewController view];
[self.view addSubview:view];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
thingViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}