Object creation order in Interface Builder

Discussion in 'Mac Programming' started by psantacr, Aug 8, 2008.

  1. psantacr macrumors newbie

    Joined:
    Feb 16, 2008
    #1
    Hi all,

    I have a MainController object I am using in COCOA to handle some global application specific tasks which are used in many other classes on my project.

    Right now, I am instantiating that object in Interface Builder and linking it to the rest of the graphical objects through an IBOutlet.

    Two quick questions:

    1) Is there a better way to achieve this? Maybe creating the MainController object by hand and associating it with each class that needs it by code instead of an outlet?

    2) Is there a way to specify the object creation order in InterfaceBuilder? This way, I am going to make sure my MainController object is created before the other objects using it.

    Thanks a lot in advance.
    :eek:
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    AFAIK, you can't change the order of how objects load in a NIB. You'll have to do it in code.

    You could just do your initialization in awakeFromNib though.
     
  3. psantacr thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #3
    Thanks for the quick response. Where should I put that code? On the main function itself? I know how to do it, but I would like to make sure I am doing it the way you are supposed to do it in Cocoa.

    I have been looking around for some code samples on this, but had no luck. Also, there aren't many Open Source COCOA projects to learn from.

    Thanks again. :apple:
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Usually you create an object in MainMenu.nib that is your app delegate. Then, in your app delegate (in code) you can initialize your other objects from a starting point such as init, or applicationDidFinishLaunching.

    http://osx.hyperjeff.net/Apps/CocoaSource.html
    http://www.cocoadev.com/index.pl?CocoaOpen
     

Share This Page