2

Is this a good way to set a custom ViewController as the rootViewController of the window?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = [[[CustomViewController alloc]init] autorelease];
    [self.window makeKeyAndVisible];
    return YES;
}

In most of Apple's examples they first declare a viewController property, and then:

RootViewController* theRVC = [[RootViewController alloc] init];
self.viewController = theRVC;
[theRVC release];

[self.window addSubview:self.rvc.view];
[self.window makeKeyAndVisible];

What is the diference between these two approaches and which is recommended?

NSExplorer
  • 11,849
  • 12
  • 49
  • 62
  • This discussion may help: http://stackoverflow.com/questions/5842087/programming-ios-clarifications-about-root-view-controller – Davyd Geyl Oct 05 '11 at 22:51

1 Answers1

2

The rootViewController property of UIWindow was recently introduced with iOS4. This new method seems to be the recommended approach advocated by Apple. Either approach works but I would stick with the new way of setting the rootViewController property only if you are not targeting early versions of iOS.

ms83
  • 1,804
  • 16
  • 13