tamasgal
tamasgal

Reputation: 26259

NSPersistentDocument – how to access the window?

I want to set some properties of the window of my NSPersistentDocument object. How do I get access to it?

Is there a better way than like this?

    [[[[self windowControllers] objectAtIndex:0] window] setBackgroundColor:[NSColor blueColor]];

Upvotes: 1

Views: 363

Answers (2)

paulmelnikow
paulmelnikow

Reputation: 17208

I'm using self.windowForSheet which seems to be working.

Upvotes: 1

Alex
Alex

Reputation: 26859

Nope, that's the way to get it. The NSWindowController is responsible for managing the window, and that's why it owns the window.

If you're customizing the window appearance or behavior, it would actually be better to subclass NSWindowController and put the code the customizes the window in that class, rather than your NSDocument/NSPersistentDocument subclass.

NSDocument (and friends) are meant to manage the data, and NSWindowController is meant to manage the UI. In all but the simplest applications, you should be subclassing NSWindowController.

Upvotes: 3

Related Questions