Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does setting the UIWindow's rootViewController do?

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

like image 667
Stanley Avatar asked Nov 20 '11 19:11

Stanley


People also ask

What is rootViewController in iOS?

The root view controller provides the content view of the window. 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.

What is Uiwindow in iOS?

The backdrop for your app's user interface and the object that dispatches events to your views. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+


1 Answers

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];
like image 152
Can Berk Güder Avatar answered Sep 21 '22 14:09

Can Berk Güder