调用addChildViewController后是否必须调用addSubview? [英] Do I have to call addSubview after calling addChildViewController?

查看:172
本文介绍了调用addChildViewController后是否必须调用addSubview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 iOS5 创建容器视图控制器,以及 addChildViewController 等新方法。

I'm trying to create a container view controller using iOS5 and new methods like addChildViewController.

调用 addChildViewController 后,我是否必须调用 addSubview

Do I have to call addSubview after calling addChildViewController?

在调用 removeChildViewController 之前,我是否必须调用 removeFromSuperview

Do I have to call removeFromSuperview before calling removeChildViewController?

我在Apple文档中没有看到任何相关内容。
您怎么看?

I don't see anything about this in Apple docs. What do you think?

推荐答案

简短回答:是的,是的。视图层次结构和视图控制器层次结构仍然是独立的。包含API只允许来自其他控制器的视图以干净和一致的方式在父控制器的视图中显示它们。

Short answer: "Yes, and yes." The view hierarchy and the view controller hierarchy are still independent. The containment API simply allows views from other controllers to present themselves within a parent controller's view in a clean and consistent way.

你可以在 Apple的文档在这里 ...这是容器视图控制器安排其他视图控制器内容部分的相关段落:

You can find a bit in Apple's docs here... this is a relevant passage from the "Container View Controllers Arrange Content of Other View Controllers" section:


容器管理视图层次结构就像其他视图控制器一样。容器还可以将其任何子项的视图添加到其视图层次结构中。容器决定何时添加这样的视图以及如何调整它以适应容器的视图层次结构,否则子视图控制器仍然负责视图及其子视图。

A container manages a view hierarchy just as other view controllers do. A container can also add the views of any of its children into its view hierarchy. The container decides when such a view is added and how it should be sized to fit the container’s view hierarchy, but otherwise the child view controller remains responsible for the view and its subviews.

如果您有权限,我强烈建议您查看WWDC 2011视频实施UIViewController遏制(在Safari中观看 | 在iTunes中查看)。

If you have access, I would highly recommend checking out the WWDC 2011 video entitled "Implementing UIViewController Containment" (watch in Safari | view in iTunes).

这篇关于调用addChildViewController后是否必须调用addSubview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆