我正在尝试做这样的事情 -
- (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];
}
它只是给我一个白屏,里面什么都没有。如果我在导航堆栈上推送新的 View Controller ,它会正确显示 Controller 。知道我可能缺少什么吗?
Best Answer-推荐答案 strong>
您应该在 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);
}
关于新 View Controller 的 iOS addSubview 不起作用,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/31459063/
|