绑定自定义NSView:是否需要创建IBPlugin? [英] Binding a custom NSView: Does it demand creating an IBPlugin?

查看:208
本文介绍了绑定自定义NSView:是否需要创建IBPlugin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个NSView的子类来绘制一个图像作为模式:

I have created a subclass of NSView to draw an image as a pattern:

@interface CePatternView : NSView
{
    NSImage*    image;
    id      observableObjectForImage;
    NSString*   keyPathForImage;
}

@end

我实现了以下操作bindings:

I implemented the following to expose bindings:

+ (void)initialize
{
    // Expose the "image" binding to IB.
    [self exposeBinding:@"image"];  
}

- (Class)valueClassForBinding:(NSString *)binding
{
    if([binding isEqualToString:@"image"])
        return [NSImage class];
    return nil; // Unknown binding
}

不幸的是,图片

我真的需要创建一个IBPlugin来暴露Interface Builder中的绑定吗?对于我不打算重用的自定义视图。

Do I really have to create an IBPlugin to expose bindings in Interface Builder? That just seems way overkill for a custom view that I don't plan to reuse.

推荐答案

标题答案不是,您可以绑定自定义视图没有IB插件(通过在代码中执行)。

对问题正文中的问题的回答:是的,您需要一个IB插件来暴露IB中的绑定。

Answer to title: No, you can bind a custom view without an IB plug-in (by doing it in code).
Answer to question in question body: Yes, you do need an IB plug-in to expose the binding in IB.

您的代码不会在Interface Builder中运行,除非将其放入Interface Builder中,并且 exposeBinding:消息是您的代码。因此,你需要把它放到Interface Builder中。这意味着要编写一个IB插件。

Your code doesn't run inside Interface Builder unless you put it into Interface Builder, and that exposeBinding: message is your code. Therefore, you need to put it into Interface Builder. That means writing an IB plug-in.

此外,IB插件与旧的IB调色板不同。插件需要IB 3,并且更容易创建。调色板需要IB 2,创建起来很痛苦。

Also, IB plug-ins are not the same as the old IB palettes. Plug-ins require IB 3 and are much easier to create. Palettes require IB 2 and were painful to create.

这篇关于绑定自定义NSView:是否需要创建IBPlugin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆