简体   繁体   中英

Accessing NSDocument from NSWindowController subclass?

I am creating simple document based app. So far I have implemented NSDocument subclass, which is Document and NSWindowController subclass, which is ToolbarWindowController . ToolbarWindowController controlls the toolbar, which has sliders to modify user's opened image.

Where I am having issue right now is applying filters (modifying image) on opened image: I can't figure out how to use opened image as source in ToolbarWindowController .

Fe when I open image in Document I can set it as ViewController imageView, in 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];
}

Can I somehow access my ToolbarWindowController properties/variables and create a NSImage property there to modify there opened image? Or can I access Document properties to achieve the same thing? Does it even work that way?

NSWindowController has a document property. If everything is hooked up properly, that property will point at the NSDocument object that owns the NSWindowController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM