设置UIWindow的rootViewController有什么作用?

发布于 2024-12-17 03:43:57 字数 538 浏览 5 评论 0原文

将视图控制器分配给此属性(以编程方式 或使用 Interface Builder)将视图控制器的视图安装为 窗口的内容视图。

上面的引用来自 UIWindow 的参考。我的问题是关于特定阶段的:

“将视图控制器的视图安装为 窗口的内容视图”

内容视图究竟指什么?

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html

Assigning a view controller to this property (either programmatically
or using Interface Builder) installs the view controller’s view as the
content view of the window.

The above quote is from the UIWindow's reference. My question is about the particular phase :

"installs the view controller’s view as the
content view of the window"

What does exactly content view refer to ?

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女 2024-12-24 03:43:57

在 rootViewController 属性出现之前,大多数应用程序在应用程序委托中都有这样的代码:

[window addSubview:viewController.view];
[window makeKeyAndVisible];

此代码将视图控制器的视图设置为主视图,但 UIWindow 实例没有引用拥有该视图的控制器。

当您使用 rootViewController 属性时,您不再需要将视图控制器的视图添加到 UIWindow 实例中,这是自动完成的。因此代码行数保持不变,但现在您的 UIWindow 具有对视图控制器的引用。

因此,在较新的应用程序中,我们现在的代码如下所示:

window.rootViewController = viewController;
[window makeKeyAndVisible];

Before the rootViewController property came along, most apps had code like this in the application delegate:

[window addSubview:viewController.view];
[window makeKeyAndVisible];

This code set the view controller's view as the main view, but the UIWindow instance had no reference to the controller owning that view.

When you use the rootViewController property, you don't need to add the view controller's view to the UIWindow instance anymore, this is done automatically. So the number of lines of code stays the same, but now your UIWindow has a reference to the view controller.

So, in newer applications, we now have code that looks like this:

window.rootViewController = viewController;
[window makeKeyAndVisible];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文