【问题标题】:NSWindow update content when show/hide显示/隐藏时 NSWindow 更新内容
【发布时间】:2016-09-26 10:45:27
【问题描述】:

我在 my.xib 文件中添加了NSWindow 元素,并在其中插入了一些元素,例如 imageView。然后创建名为customNSWindow 的NSWindow 类型的类并将这些类分配给我创建的xib 元素(NSWindow)。现在从另一个 WindowController 我需要显示/隐藏 customNSWindow。这是通过在 WindowController 上放置一个插座来完成的。

viewController.h

@property (strong) IBOutlet NSWindow *ImageEditWindow;//(custom window)

viewController.mm

-(IBAction)ButtonClick:(id)sender {
    if(! [_ImageEditWindow isVisible] ){
        [_ImageEditWindow makeKeyAndOrderFront:sender];
    }
}

但我不知道如何更新ImageEditWindow 中的图像,我找不到在我创建的自定义类中调用方法的方法,使用_ImageEditWindow 插座。

编辑

这是 NSWindow 的自定义类

CustomIKImageEditor.h

@interface CustomIKImageEditor : NSWindow
@property (weak) IBOutlet IKImageView *IKImg;
-(void) updateIKImage: (NSImage*)staticImageToEdit;
@end

CustomIKImageEditor.mm

-(void) updateIKImage: (NSImage*)staticImageToEdit {

    NSDictionary*           _imageProperties;
    CGImageRef source = [self CGImageCreateWithNSImage: staticImageToEdit];
    _imageProperties = NULL; 
    [_IKImg setImage: source  imageProperties: NULL];
}

【问题讨论】:

    标签: objective-c macos nswindow


    【解决方案1】:

    这一行:

    @property (strong) IBOutlet NSWindow *ImageEditWindow;//(custom window)

    应该是:

    @property (strong) IBOutlet CustomIKImageEditor *ImageEditWindow;//(custom window)

    【讨论】:

    • 我试过[_ImageEditWindow updateIKImage:staticImageToEdit];,但收到类似No visible @interface for 'NSWindow' declares the selector 'updateIKImage:'的错误消息
    猜你喜欢
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多