菜鸟教程小白 发表于 2022-12-12 15:08:21

ios - subview Controller 的 View 未显示在容器中


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

<p>所以,在父 <code>UIViewController</code> 我定义了属性:</p>

<pre><code>@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (strong, nonatomic) MyChildViewController *childController;
</code></pre>

<p>然后,在父级的 <code>viewDidLoad</code> 方法中,我这样做:</p>

<pre><code>if (self.childController == nil) {
    self.childController = [ init];
}

;
self.childController.view.frame = CGRectMake(0, 0, self.containerView.frame.size.width, self.containerView.frame.size.height);
;
;
</code></pre>

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

<p>谢谢</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我终于注意到我忽略了...因为我还在 Storyboard 中为 <code>MyChildViewController</code> 创建了一个场景,所以我需要从那里实例化它。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios -subviewController 的 View 未显示在容器中,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/29878657/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/29878657/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - subview Controller 的 View 未显示在容器中