0
votes

I am new to document-based applications and hence I may have missed something fundamental. I have written a document based application which uses a subclassed NSWindowController for the interface and a subclassed NSDocument for the model. Per the documentation I initialise the windowController in makeWindowControllers and load its xib. In interface builder, the xib has my windowController subclass set as File's Owner. Among the views in the window, I have a subclass of NSOutlineView and the NSOutlineView datasource and delegate are also refenced in the nib and connected to the windowController via IBOutlets.

According to the documentation, I should be able to access the document from the OutlineView datasource via [windowController document]. However, referencing the windowController (via IBOutlet) from the OutlineView datasource gives me the document instead!

This has lead to some rather ugly code in the OutlineView datasoure (which is a subclass of NSObject in the windowController's xib) to get hold of the document, eg:

-(MyDocument *)myDocument {
    MyDocument *theDocument = (MyDocument *)myWindowController;
    return theDocument;
}

Where the IBOutlet in the header file references myWindowController as:

IBOutlet MyWindowController *myWindowController

In brief - why does an IBOutlet connected to the windowController get me the document directly instead in this situation? The above code works but seems as if it shouldn't.

Edit: clarification

1
Which class acts as the outline view data source, and where do you create an instance of this class?user557219
Without having access to the nib file and the source code, I can’t think of a reason why you’re having this problem. If the class that acts as the outline view data source has an IBOutlet connected to File’s Owner then it should be the window controller instance. If you’re willing to upload your project somewhere, I could take a look at it.user557219
Thanks for replying! The outlineView datasource is an NSObject created in the windowController's xib, connected to File's Owner through an IBOutletGeebs

1 Answers

0
votes

Okay, I worked out the answer to this one - don't accidentally set the File's Owner of the xib to the NSDocument instead of the windowController in another part of your code and forget that you did it! This overrides the File's Owner that you previously set in the xib.