Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

typecase

macrumors 6502
Original poster
Feb 2, 2005
390
397
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

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
typecase said:
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

macrumors 6502
Original poster
Feb 2, 2005
390
397
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

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
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:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.