NSCollectionView 位于另一个 NSCollectionView 中

发布于 2024-09-15 12:08:33 字数 967 浏览 7 评论 0原文

我有这两个类:

@interface Father : NSObject
{
     NSString* name;
     NSArray* listChildren;
}

@property (copy, readwrite) NSString* name;
@property (copy, readwrite) NSArray* listChildren;

@end

@interface Child : NSObject
{
     NSString* nameChild;
     NSImage* picture;
}

@property (copy, readwrite) NSString* nameChild;
@property (copy, readwrite) NSImage* picture;

@end

我正在尝试创建一个充满 Father 项目的 NSCollectionView ,对于每个父亲项目的 View 我将有一个name 标签,另一个 NSCollectionView 填充了(父亲)representedObject.listChildren 项。

我已设法为父 NSCollectionViewItemView 创建一个外部 NIB 文件以使事情变得更容易,但我无法绑定子 CollectionViewrepresentedObject.listChildren 属性。实际上,在 IB 中绑定没有问题,并且在运行时系统实际上正在调用该属性(我添加了 getListChildren 实现和 NSLog 调用以确保正在调用该属性)。内部的 CollectionView 似乎不会加载在我的 NSArray* 属性中找到的项目?

这让我发疯,对发生的事情有什么想法吗? 请帮忙!!

I have these two classes:

@interface Father : NSObject
{
     NSString* name;
     NSArray* listChildren;
}

@property (copy, readwrite) NSString* name;
@property (copy, readwrite) NSArray* listChildren;

@end

@interface Child : NSObject
{
     NSString* nameChild;
     NSImage* picture;
}

@property (copy, readwrite) NSString* nameChild;
@property (copy, readwrite) NSImage* picture;

@end

I'm trying to make a NSCollectionView filled with Father items, and for each father item's View i will have a name label, and another NSCollectionView filled with the (father) representedObject.listChildren items.

I've managed to create an external NIB file for the father NSCollectionViewItem's View to make things easier, but I'm not able to bind the child CollectionView to the representedObject.listChildren property. Actually, there is no problem in binding in IB, and at runtime the system is actually calling the property (I've added and getListChildren implementation and a NSLog call to make sure the property is being called). It seems that the inner CollectionView's won't load the items found in my NSArray* property?

It is driving me crazy, any ideas about what is going on?
Help please!!

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

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

发布评论

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

评论(1

只是一片海 2024-09-22 12:08:33

我遇到了完全相同的问题,并且找到了解决方案!

我对 Objective C 和 Cocoa 完全是新手,所以我不完全理解为什么这不起作用的原因。也许其他人可以启发我们。

在我的第一次尝试中,我只是在默认的 MainMenu.xib 中完成了所有操作。这样你最终会得到两个 NSArrayController 。现在显然,正如您所怀疑的,问题出在内部项目的第二个 NSArrayController 上。它以某种方式无法正确“复制”。将每个 NSView 提取到其自己的 .xib 中可以解决此问题。

实际上这个讨论让我着迷朝着正确的方向开始。我后来发现/明白,这与 @user493638 已经暗示的想法基本相同。

将这些知识与此处的教程相结合,了解如何将视图提取到他们自己的 .xib 为我解决了问题!

再说一次,我对 Objective C 和 Cocoa 的理解还不够充分,无法完全理解这种行为的根本原因,谁知道所有这些绑定魔法到底是如何在幕后工作的......

I had the exact same problem and I found the solution!

I'm a complete novice to Objective C and Cocoa so I don't fully understand the reasons why this does not work exactly. Maybe somebody else can enlighten us.

In my first try I simply did everything in the default MainMenu.xib. You end up with two NSArrayController this way. Now apparently, as you suspected, the issue lies with the second NSArrayController for the inner items. It somehow doesn't get "copied" correctly. Extracting each NSView into its own .xib solves this issue.

Actually this discussion got me started in the right direction. I later discovered/understood that this is the basically the same idea @user493638 already hinted at.

Combining this knowledge with the tutorial here, on how to extract the views into their own .xib solved the problem for me!

Again I don't understand Objective C and Cocoa nearly enough to fully appreciate the underlying reasons for this behavior, who knows how exactly all this binding magic works under the hood...

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