PDA

View Full Version : Help needed with startup action




typecase
Nov 14, 2005, 03:30 PM
I've written my second cocoa application and all is well so far except that currently have to hit a button that calls a controller method to execute the program's main code. How do I have this method invoked at startup? Any help very much appreciated.



caveman_uk
Nov 15, 2005, 05:48 AM
I've written my second cocoa application and all is well so far except that currently have to hit a button that calls a controller method to execute the program's main code. How do I have this method invoked at startup? Any help very much appreciated.
Your question is a bit vague but can you put your code in either init or awakeFromNib?

typecase
Nov 16, 2005, 11:40 PM
Thanks for the reply Caveman UK! Sorry for the vagueness. Basically I have a function in my code that I only know how to call by pushing a button linked to the function. I was wondering how to call the funtion automatically at startup. I think you've given me my answer, Init or awakefromnib. I'll have to try it this weekend. Thanks again. :D

caveman_uk
Nov 17, 2005, 03:09 AM
There are differences between the two. Basically in the simple case (where you have a controller and MainMenu.nib) awakeFromNib is called after your GUI is loaded so all your outlets exist. init is called when the class is init'd (obviously) so your GUI outlets probably (definately?) won't exist.

I forgot to mention you could also make your controller the app delegate and write an implementation of

- (void)applicationDidFinishLaunching: (NSNotification* )aNotification;

which is called after everything's loaded but before the app is sent it's first event.

There are definite reasons for doing things at different times because your app may receive other messages (such as openFiles when the app is launched by clicking a document icon) before applicationDidFinishLaunching: