2011-10-07 64 views
1

我想設置我的NSPersistentDocument對象的窗口的一些屬性。我如何訪問它?NSPersistentDocument - 如何訪問窗口?

有沒有比這樣更好的方法?

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

回答

3

不,這是得到它的方法。 NSWindowController負責管理窗口,這就是它擁有窗口的原因。

如果您自定義窗口外觀和行爲,它實際上是更好的繼承NSWindowController並把代碼中的自定義窗口在類,而不是你的NSDocument/NSPersistentDocument子類。

NSDocument(和朋友)是爲了管理數據,並且NSWindowController是爲了管理UI。除最簡單的應用程序外,您應該繼續使用NSWindowController

+0

好的,謝謝;-)我會這麼做! – tamasgal

1

我正在使用self.windowForSheet這似乎是工作。