gpt4 book ai didi

新 View Controller 的 iOS addSubview 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:52 26 4
gpt4 key购买 nike

我正在尝试做这样的事情 -

- (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 。知道我可能遗漏了什么吗?

最佳答案

您应该在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com