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]];
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
.
I'm using self.windowForSheet
which seems to be working.
精彩评论