16

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

jrturton
  • 118,105
  • 32
  • 252
  • 268
Stanley
  • 4,446
  • 7
  • 30
  • 48

1 Answers1

43

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];
Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • 6
    +1 for comprehensive answer taking historical reasoning into account – Till Nov 20 '11 at 19:35
  • Note that it's available in 4.0+ – d.lebedev Nov 20 '11 at 20:17
  • @CanBerkGüder is it true only rootviewcontroller will get the callback functions like didReceivememoryWarning? – S.J May 03 '13 at 07:35
  • @S.J Each of the view controllers pushed to the navigation controller receives the `didReceivememoryWarning` invocation. Try it yourself and see. Implement the `didReceivememoryWarning` method, have that method call NSLog, then simulate the low memory condition in the iOS Simulator. – Basil Bourque Aug 25 '13 at 23:26