1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Help needed with startup action

Discussion in 'Mac Programming' started by typecase, Nov 14, 2005.

  1. macrumors regular

    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.
  2. Guest


    Your question is a bit vague but can you put your code in either init or awakeFromNib?
  3. macrumors regular

    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
  4. Guest


    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:

Share This Page