I am currently running the following code as part of a simple test iPad program. I’ve declared “viewController” as a property. In all other examples I’ve seen involving subviews, I’ve been required to alloc and init the viewController, but here it works fine. Any ideas?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Why does this work without allocating or initializing viewController?
[self.window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
This looks like the typical boilerplate code Apple supplies with the iOS templates. In these projects the viewController is defined in the
MainWindowNIB. This NIB is loaded very early in the process of starting the app. The viewController is allocated in the NIB loading process, andinitWithNibName:bundle:is then called. The NIB loading process then connects the initialized object to the view controller’sIBOutletof the app delegate.