0

我正在创建简单的基于文档的应用程序。到目前为止,我已经实现了 NSDocument 子类Document和 NSWindowController 子类,即ToolbarWindowController. ToolbarWindowController 控制工具栏,它有滑块来修改用户打开的图像。

我现在遇到的问题是在打开的图像上应用过滤器(修改图像):我无法弄清楚如何将打开的图像用作ToolbarWindowController.

Fe 当我在其中打开图像时,Document我可以将其设置为ViewControllerimageView,在makeWindowControllers

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
    image = [[NSImage alloc] initWithData:data];
    return YES;
}
- (void)makeWindowControllers {
    NSStoryboard* const storyboard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
    NSWindowController* const windowController = [storyboard instantiateControllerWithIdentifier:@"Document Window Controller"];
    [[((ViewController *)[windowController contentViewController]) imageView] setImage:image];

    [self addWindowController: windowController];
}

我可以以某种方式访问​​我的ToolbarWindowController属性/变量并在那里创建一个NSImage属性来修改打开的图像吗?或者我可以访问Document属性来实现同样的事情吗?它甚至可以这样工作吗?

4

1 回答 1

4

NSWindowController有财产document。如果一切都正确连接,该属性将指向NSDocument拥有NSWindowController.

于 2018-11-07T17:57:34.610 回答