假设我已经创建了一个新的Cocoa应用程序,并在创建项目时使用了Document-based application。它将有一个窗口,来自NSDocument子类的窗口。如何使两个(或更多)窗口属于每个文档?
我创建了一个带有NSWindowController文件的.xib子类,在其中我创建了接口。我该怎么展示这扇窗户?NSWindowController子类和NSDocument子类之间的通信是如何工作的?
(我使用核心数据,因此它实际上是一个NSPersistentDocument子类,但我认为这对这个特定问题并不重要。)
发布于 2014-08-19 12:28:23
在你的NSDocument
//Lazy instantiation of window controller
- (AdditionalWindowController *)additionalWC {
if (!_additionalWC) {
_additionalWC = [[AdditionalWindowController alloc] initWithWindowNibName:@"AdditionalWindow"];
}
return _additionalWC;
}
- (IBAction)openAdditionalWindow:(id)sender {
self.additionalWC.document = self;
[self.additionalWC showWindow:self];
}或
- (IBAction)openAdditionalWindow:(id)sender {
//addWindowController ignores redundant invocations.
[self addWindowController:self.additionalWC];
[self.additionalWC showWindow:self];
}在您的AdditionalWindowController中,您始终可以调用
id document = [self document];
//do what ever you want e.g. somethingDidChanged | direct method call of your documenthttps://stackoverflow.com/questions/25382903
复制相似问题