IBPlugin:从 IB 库拖动时添加其他对象

发布于 2024-09-24 21:06:31 字数 1697 浏览 2 评论 0原文

我有一个列表视图类,就像 NSCollectionView 需要额外的原型项和原型视图才能使用。 当从 Interface Builder 中的库中删除 NSCollectionView 时,会自动创建这两个辅助项。然而,我找不到处理此用例的单个苹果官方文档(描述其如何完成)。

然而,通过挖掘苹果开发指南,我可以找到“ibDidAddToDesignableDocument:“。
使用以下代码,我设法从库中删除时创建辅助项目:

- (void)ibDidAddToDesignableDocument:(IBDocument *)document {
    [super ibDidAddToDesignableDocument:document];

    NSView *prototypeView = [[[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 65.0)] autorelease];
    DLListViewItem *prototypeViewItem = [[[DLListViewItem alloc] initWithNibName:nil bundle:nil] autorelease];

    [document addObject:prototypeViewItem toParent:nil];
    [document addObject:prototypeView toParent:nil];

    [document connectOutlet:@"view" ofSourceObject:prototypeViewItem toDestinationObject:prototypeView];
    [document connectOutlet:@"listView" ofSourceObject:prototypeViewItem toDestinationObject:self];
    [document connectOutlet:@"prototypeItem" ofSourceObject:self toDestinationObject:prototypeViewItem];
}

但是...

...IB 在实际初始拖动上为 NSCollectionView 添加这些辅助项目来自库,而不是在“ibDidAddToDesignableDocument:”的任何其他调用上,例如在嵌入、复制或复制项目时。 (虽然我的方法会,而且最重要)

这让我想知道苹果是否真的使用“ibDidAddToDesignableDocument:”来实现这一点,以及我是否走在正确的轨道上。

如何正确地模仿这一点?我很难区分“ibDidAddToDesignableDocument:”的不同上下文。有人成功做到这一点吗?
不幸的是,谷歌、谷歌代码、GitHub 或文档都没有透露任何有用的信息,所以我在这里迫切需要帮助。 :(

预先感谢!

编辑:哦太好了,这个问题刚刚给我带来了风滚草徽章,是的!不是。
实际上我更喜欢有用的答案,但无论如何还是谢谢;)

I have a list view class that just like NSCollectionView requires an additional prototype item and a prototype view to be of any use.
When dropping an NSCollectionView from the library in Interface Builder those two helper items are automatically created. However I couldn't find a single official Apple document dealing with this use case (describing how its done).

Digging thru the Apple Dev Guides I could however find "ibDidAddToDesignableDocument:".
With the following code I managed to get my auxiliary items created on drop from library:

- (void)ibDidAddToDesignableDocument:(IBDocument *)document {
    [super ibDidAddToDesignableDocument:document];

    NSView *prototypeView = [[[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 65.0)] autorelease];
    DLListViewItem *prototypeViewItem = [[[DLListViewItem alloc] initWithNibName:nil bundle:nil] autorelease];

    [document addObject:prototypeViewItem toParent:nil];
    [document addObject:prototypeView toParent:nil];

    [document connectOutlet:@"view" ofSourceObject:prototypeViewItem toDestinationObject:prototypeView];
    [document connectOutlet:@"listView" ofSourceObject:prototypeViewItem toDestinationObject:self];
    [document connectOutlet:@"prototypeItem" ofSourceObject:self toDestinationObject:prototypeViewItem];
}

However…

IB adds those aux items for NSCollectionView only on the actual initial drag from the library, not on any other call of "ibDidAddToDesignableDocument:", such as when embedding, copying or duplicating the item. (while my method would, and on all)

This makes me wonder whether Apple actually uses "ibDidAddToDesignableDocument:" for this and if I'm on the right track with this at all.

How does one imitate this properly? I'm having a hard time trying to distinguish between different contexts for "ibDidAddToDesignableDocument:". Anybody successfully done this?
Unfortunately none of Google, Google Code, GitHub, or the documentation revealed anything helpful, so I'm in desperate need of help here. :(

Thanks in advance!

Edit: Oh great, this question just brought me the tumbleweed badge, yay! Not.
I'm more into useful answers actually, but thanks anyway ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假情假意假温柔 2024-10-01 21:06:31

我在不久前自己做的一个插件上遇到了这个问题。就我而言,我能够检查对象的属性以查看它是否已初始化,并在这种情况下跳过添加辅助对象。我相信 BWToolkit 使用一些类似的内部检查。您不能检查对象的“prototypeItem”属性来查看是否需要跳过创建辅助对象吗?

I struggled with this on a plugin I did myself a while ago. In my case I was able to check a property of the object to see if it had been initialized already and skip adding the auxilliary objects in that case. I believe BWToolkit uses some internal checking that is similar. Couldn't you check your object's 'prototypeItem' property to see if you need to skip creating your aux objects?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文