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.
以上引用来自 UIWindow 的引用。我的问题是关于特定阶段的:
"installs the view controller’s view as the content view of the window"
内容 View 到底指的是什么?
最佳答案
在 rootViewController
属性出现之前,大多数应用程序在应用程序委托(delegate)中都有这样的代码:
[window addSubview:viewController.view];
[window makeKeyAndVisible];
此代码将 View Controller 的 View 设置为主视图,但 UIWindow 实例没有引用拥有该 View 的 Controller 。
当您使用 rootViewController
属性时,您不再需要将 View Controller 的 View 添加到 UIWindow 实例,这是自动完成的。因此代码行数保持不变,但现在您的 UIWindow 具有对 View Controller 的引用。
因此,在较新的应用程序中,我们现在的代码如下所示:
window.rootViewController = viewController;
[window makeKeyAndVisible];
关于iphone - 设置 UIWindow 的 rootViewController 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8204059/