OGeek|极客世界-中国程序员成长平台

标题: ios - subview Controller 的 View 未显示在容器中 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:08
标题: ios - subview Controller 的 View 未显示在容器中

我在 Storyboard 中有一个带有 Container View 的场景。正如您可能猜想的那样,我希望其关联的 UIViewController 加载另一个 UIViewController 作为 subview Controller ,并将其 View 显示为 subview 。

所以,在父 UIViewController 我定义了属性:

@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (strong, nonatomic) MyChildViewController *childController;

然后,在父级的 viewDidLoad 方法中,我这样做:

if (self.childController == nil) {
    self.childController = [[MyChildViewController alloc] init];
}

[self addChildViewController:self.childController];
self.childController.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
[self.containerView addSubview:self.childController.view];
[self.childController didMoveToParentViewController:self];

self.childController.viewself.containerView都不是nil,而是self.childController.view 运行应用程序时不显示...我可能缺少什么?

谢谢



Best Answer-推荐答案


我终于注意到我忽略了...因为我还在 Storyboard 中为 MyChildViewController 创建了一个场景,所以我需要从那里实例化它。

关于ios - subview Controller 的 View 未显示在容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29878657/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4