When are outlets initialised?

  • Hiya,

    When are outlets initialised? Following is the scenario where I come
    across null outlets.

    I have a window with a NSTableView that displays a list of users.
    I have a NSWindowController subclass called UsersController with an
    outlet called usersTable.
    The NSTableView is connected to the usersTable outlet.

    I open the window with:
    usersWindow = new UsersController(); }
    usersWindow.window().makeKeyAndOrderFront(this);

    In UsersController is the 'windowDidLoad' method. In this method I want
    to set the data source for a table view but the usersTable outlet is
    null.

    windowDidLoad gives me the impression that the window did load, but
    loading the window doesn't initialise the outlets. When does that happen?

        public void windowDidLoad() {
    // Get the model for this view
            model = applicationDeligate.getLicenseHolder().getUsers();
            usersTable.setDataSource(this);
        }

    The above dies on the last line because usersTable is null.

    Thanks again,

    Phil
  • See -awakeFromNib

    ----- Original Message -----
    From: "Phil Blake" <phil...>
    To: <macosx-dev...>
    Sent: Wednesday, October 10, 2001 1:18 AM
    Subject: When are outlets initialised?

    > Hiya,
    >
    > When are outlets initialised? Following is the scenario where I come
    > across null outlets.
    >
    > I have a window with a NSTableView that displays a list of users.
    > I have a NSWindowController subclass called UsersController with an
    > outlet called usersTable.
    > The NSTableView is connected to the usersTable outlet.
    >
    > I open the window with:
    > usersWindow = new UsersController(); }
    > usersWindow.window().makeKeyAndOrderFront(this);
    >
    > In UsersController is the 'windowDidLoad' method. In this method I want
    > to set the data source for a table view but the usersTable outlet is
    > null.
    >
    > windowDidLoad gives me the impression that the window did load, but
    > loading the window doesn't initialise the outlets. When does that happen?
    >
    > public void windowDidLoad() {
    > // Get the model for this view
    > model = applicationDeligate.getLicenseHolder().getUsers();
    > usersTable.setDataSource(this);
    > }
    >
    > The above dies on the last line because usersTable is null.
    >
    > Thanks again,
    >
    > Phil
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • Am Mittwoch den, 10. Oktober 2001, um ?:18, schrieb Phil Blake:

    > Hiya,
    Mahlzeit

    >
    > When are outlets initialised? Following is the scenario where I come
    > across null outlets.
    >
    > I have a window with a NSTableView that displays a list of users.
    > I have a NSWindowController subclass called UsersController with an
    > outlet called usersTable.
    > The NSTableView is connected to the usersTable outlet.
    >
    > I open the window with:
    > usersWindow = new UsersController(); }
    > usersWindow.window().makeKeyAndOrderFront(this);
    >
    > In UsersController is the 'windowDidLoad' method. In this method I want
    > to set the data source for a table view but the usersTable outlet is
    > null.
    Have you done all connection right in Interface Builder?
    Set the Files Owner to "UsersController", so the outlet name appears in
    the inspector and then ctrl-drag from the files owner to the tabView?
    Also: Look at the inspector window. It shows you the type of class the
    selected object has. You could easily have connected to the embedding
    scrollview and NOT the tableView. The tableView is the inner part. The
    column headers are also separate objects.

    Stefan
    >
    > windowDidLoad gives me the impression that the window did load, but
    > loading the window doesn't initialise the outlets. When does that
    > happen?
    >
    > public void windowDidLoad() {
    > // Get the model for this view
    > model = applicationDeligate.getLicenseHolder().getUsers();
    > usersTable.setDataSource(this);
    > }
    >
    > The above dies on the last line because usersTable is null.
    >
    > Thanks again,
    >
    > Phil
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
    >
  • From: "Phil Blake" <phil...>
    Sent: Wednesday, October 10, 2001 1:18 AM
    >
    > When are outlets initialised? Following is the scenario where I come
    > across null outlets.
    >
    > I have a window with a NSTableView that displays a list of users.
    > I have a NSWindowController subclass called UsersController with an
    > outlet called usersTable.
    > The NSTableView is connected to the usersTable outlet.
    >
    > I open the window with:
    > usersWindow = new UsersController(); }
    > usersWindow.window().makeKeyAndOrderFront(this);
    >
    > In UsersController is the 'windowDidLoad' method. In this method I want
    > to set the data source for a table view but the usersTable outlet is
    > null.
    >
    > windowDidLoad gives me the impression that the window did load, but
    > loading the window doesn't initialise the outlets. When does that happen?

    I ran into the same problem, and found out that you need to do something like:
    usersWindow = new UsersController();
    mywindow = usersWindow.window();    <=== outlets are initialized
    during this call
    ... set the data source here
    mywindow.makeKeyAndOrderFront(this);

    windowDidLoad is called before the outlets are initialized, as you saw.

    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "Originality is the art of concealing your sources."
    http://www.brockerhoff.net/ (updated Oct. 2001)
  • Hi,

    Thanks for your reply.

    It certainly helped. I've managed to set the usersTable correctly. :)

    However, now there's something new...

    usersWindow().window(); always returns null (although the window loads
    and opens when window() is called)

    Anyone seen this? Why would window() return null when it has clearly
    loaded and opened the window successfully.

    From the manual: Returns the window owned by the receiver or null if
    there isn't one.

    Does the sentence in the manual have another interpretation that I've
    missed?

    > I ran into the same problem, and found out that you need to do
    > something like:
    > usersWindow = new UsersController();
    > mywindow = usersWindow.window();    <=== outlets are initialized during
    > this call
    > ... set the data source here
    > mywindow.makeKeyAndOrderFront(this);
    >
    > windowDidLoad is called before the outlets are initialized, as you saw.

    Thanks,

    Phil
  • At 10:23 +1000 on 11/10/2001, Phil Blake wrote:

    > Hi,
    >
    > Thanks for your reply.
    >
    > It certainly helped. I've managed to set the usersTable correctly. :)
    >
    > However, now there's something new...
    >
    > usersWindow().window(); always returns null (although the window loads and opens when window() is called)
    >
    > Anyone seen this? Why would window() return null when it has clearly loaded and opened the window successfully.

    As far as I could find out, it always returns null. To get at the window, you apparently need to put an outlet to it into the window's owner.

    I forgot to mention this, and the third line:
    mywindow.makeKeyAndOrderFront(this);
    will probably fail because of this. Sorry about that...

    >> From the manual: Returns the window owned by the receiver or null if there isn't one.
    >
    > Does the sentence in the manual have another interpretation that I've missed?

    No, it's quite weird...

    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "Originality is the art of concealing your sources."
    http://www.brockerhoff.net/ (updated Oct. 2001)
  • > usersWindow().window(); always returns null (although the window
    > loads and opens when window() is called)
    >
    > Anyone seen this? Why would window() return null when it has clearly
    > loaded and opened the window successfully.
    >
    >> From the manual: Returns the window owned by the receiver or null
    > if there isn't one.
    >
    > Does the sentence in the manual have another interpretation that I've missed?

    Assuming that usersWindow is your windowcontroller, you have to bind
    your window instance in your nib file to the window controller's
    (File's Owner) 'window' binding in interface builder.  I agree that
    the documentation isn't clear on this point.

    Avi Cherry
  • On Thursday, October 11, 2001, at 01:31  am, Rainer Brockerhoff wrote:

    > As far as I could find out, it always returns null. To get at the
    > window, you apparently need to put an outlet to it into the window's
    > owner.

    That's a bug in Cocoa Java then. -[NSWindowController window] works fine
    here.

      -- Finlay
  • At 07:33 +0100 on 11/10/2001, Finlay Dobbie wrote:

    > On Thursday, October 11, 2001, at 01:31  am, Rainer Brockerhoff wrote:
    >
    >> As far as I could find out, it always returns null. To get at the window, you apparently need to put an outlet to it into the window's owner.
    >
    > That's a bug in Cocoa Java then. -[NSWindowController window] works fine here.

    With me, in Objective-C, it never did. At least not right after creating the window... it may return something after calling makeKeyAndOrderFront, I never checked.

    Unless you need to connect it up explicitly in IB? If so, the documentation doesn't mention this.

    --
    Rainer Brockerhoff  <rainer...>
    Belo Horizonte, Brazil
    "Originality is the art of concealing your sources."
    http://www.brockerhoff.net/ (updated Oct. 2001)
  • At 10:26 AM -0300 10/11/01, Rainer Brockerhoff wrote:
    > Unless you need to connect it up explicitly in IB? If so, the
    > documentation doesn't mention this.

    I guess you didn't get my earlier message.  You need to explicitly
    connect the 'window' outlet of your NSWindowController or subclass
    (which should be the File's Owner in the NIB file) to its window.
    And yes, the documentation doesn't mention this.