iphone - 设置 UIWindow 的 rootViewController 有什么作用?

标签 iphone ios cocoa-touch uiviewcontroller uiwindow

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 到底指的是什么?

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

最佳答案

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/

相关文章:

iphone - 以模态方式呈现 UIImagePickerController 时出错

ios - 具有相同选项卡 Controller 的多个 View Controller

ios - 使用 RestKit 0.20 与 JSON 数组的 CoreData 映射?

ios - 如何捕获 WebKit 错误

ios - 如何检测 iPhone X 主页指示灯?

objective-c - 以编程方式显示 MPMoviePlayerController 中的控件

ios - 点击对焦但曝光不起作用

iphone - 使用 tableView willDisplayCell 自定义 tableview 背景 : delegate method

iphone - ABPersonViewController CF 是否保留其显示的Person ABRecordRef?

ios - 单击导航栏按钮下方的区域时,将触发导航栏按钮单击事件。