and thanks for taking a look at my problem.
i have two view controllers in my app and each has its own nib file. an instance of controller1 is stored in MainWindow.xib and an instance of controller 2 is in Controller1.xib.
is there a way to make sure that controller 2 is initialized before t开发者_运维百科he app delegate is sent applicationDiDFinishLaunching?
the actual setup is much more complicated with many other view controllers, so i really don't want to put everything into MainWindow.xib. plus doing so will reduce reusability.
thanks again!
is there a way to make sure that controller 2 is initialized before the app delegate is sent
applicationDiDFinishLaunching
?
No. Well, maybe yes, but it's not how view controllers are supposed to work. The view controller is there to defer the loading of the nib, which is a rather expensive operation, until the view is really, really necessary. So, if you need controller2
right when applicationDidFinishLaunching
is called, you shouldn't put it inside the nib which is controlled by another view controller.
If I were you, I would stop instantiating the view controllers in the nib file at all, and just create them inside applicationDidFinishLaunching:
, as in
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
....
self.controller2=[[Controller2 alloc] init... ];
....
}
I believe applicationDidFinishLaunching
is the absolute entry point in which you have control of the code. That's conceivably the earliest place to load anything.
精彩评论