cocoaxibnswindownibnswindowcontroller

Owner other than window controller in [NSWindowController initWithWindowNibName:owner]?


What I would like to know is how does the window controller I initialize with

NSWindowController *c=[[NSWindowController alloc] initWithWindowNibName:@"Win" owner:myObj]

know which window it should control in the Win.xib file if myObj is not the controller itself? Normally I set the window controller as the owner so that I can set its window in IB with on outlet. Is memory management done all by the window controller even if it is not the owner?


Solution

  • The window controller will do the memory management of the top-level objects even if it's not the owner. From the NSWindowController class reference:

    Regardless of who is the file’s owner, the window controller is responsible for freeing all top-level objects in the nib file it loads.

    The window controller is normally the owner of the NIB, though, and connecting its window outlet is usually how it knows which window to control. One could also use the -setWindow: method to set it explicitly.

    It's conceivable that NSWindowController searches the NIB's top-level objects for a window to control if the outlet isn't hooked up, but I don't think it does that.

    Have you observed some behavior that you don't understand? What was it?