Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

self.window.rootViewController vs window addSubview

I've noticed a lot of examples for iPhone apps in the Application Delegate

- (void)applicationDidFinishLaunching:(UIApplication *)application

have

[window addSubview: someController.view]; (1)

as opposed to

self.window.rootViewController = self.someController; (2)

Is there any practical reason to use one over the other? Is one technically correct? Do controller's have an equivalent command to number (2) like

self.someController.rootController = self.someOtherController; // pseudocode

like image 212
Gazzer Avatar asked Mar 09 '11 16:03

Gazzer


Video Answer


2 Answers

The UIWindow rootViewController property is new with iOS4.

The older technique was to use addSubview.

The new, recommended technique is to set rootViewController.

like image 136
TomSwift Avatar answered Oct 10 '22 00:10

TomSwift


Just an update on this with the release of ios 6.

If still using the -[UIWindow addsubview:] boilerplate, you will probably get the message "Application windows are expected to have a root view controller at the end of application launch" in your console as well now. Along with potential rotation issues and layout issues in your app.

Setting the window's rootViewController as above will fix this too.

like image 28
jaseelder Avatar answered Oct 10 '22 01:10

jaseelder