foobar5512
foobar5512

Reputation: 2490

NSDocumentController newDocument:

I am trying to override newDocument: in my Cocoa Document Based Application. I have a standard project where when New is clicked in the menu bar, the First Responder receives the action. My goal is to have a window appear with new document configurations when New is clicked in the menu bar (sort of like Photoshop). After reading the Apple Docs, I have found that I need to override newDocument: in a NSDocumentController subclass. I then set that a configuration window should appear when newDocument: is called.

What is the best way to use my NSDocumentContoller subclass? I could drag an object out in Interface Builder and connect the method to the MainMenu bar, but I'm not sure that is good practice. How should I use my NSDocumentController as the new first responder for my MenuBar?

Upvotes: 4

Views: 1739

Answers (1)

dafi
dafi

Reputation: 3532

The NSDocumentController is a singleton and you must access to your subclass always using the method [NSDocumentController sharedDocumentController] to agree with this point you should

  • In maimenu.xib drag an NSObject and point the Custom Class to your NSDocumentController subclass, this is necessary because the Cocoa ecosystem creates the singleton before any other class

Then you can override your - (IBAction)newDocument:(id)sender and do what you prefer.

It's a bit old but I found very useful the Seashore source code when I needed to subclass NSDocumentController

The image below shows the elements in XCode enter image description here

Upvotes: 6

Related Questions