您需要实现什么来为 NSArrayController 提供内容集?

发布于 2024-08-29 01:15:55 字数 695 浏览 3 评论 0原文

嘿,

我正在 Xcode 中写一些东西。我使用 Core Data 来实现持久性,并使用 Cocoa Bindings 将视图和模型链接在一起;几乎就是普通的 Core Data 应用程序。

我的 Xib 中有一个数组控制器 (NSArrayController)。按照惯例,它的 ManagedObjectContext 绑定到 AppDelegate,并跟踪实体。到目前为止,一切都很好。

现在,此 NSArrayController 的“内容集”投标通过另一个 NSArrayController (otherAc.selection.detailsOfMaster) 中的选择的 keyPath 来限制其内容集(如您所料)。这是实现主从关系的常用方法。

我想使用其他控件在运行时可变地更改关键路径。这样,我将返回一个包含其他几个内容集的内容集,这些内容集都是高级的,超出了 Interface Builder 的范围。

为了实现这一目标,我认为我应该将内容集绑定到我的 AppDelegate。我尝试过这样做,但不知道要实施什么方法。如果我只创建 KVC 方法(objectSet、setObjectSet),那么我可以在 contentSet 方法中为数组控制器提供内容集。

但是,我认为我没有正确绑定它,因为它不会“刷新”。我是绑定新手;当其他事情(例如主 NSArrayController 中的选择)发生变化时,我需要实现什么才能正确更新内容集?

Heys,

I am writing something in Xcode. I use Core Data for persistency and link the view and the model together with Cocoa Bindings; pretty much your ordinary Core Data application.

I have an array controller (NSArrayController) in my Xib. This has its managedObjectContext bound to the AppDelegate, as is convention, and tracks an entity. So far so good.

Now, the "Content Set" biding of this NSArrayController limits its content set (as you'd expect), by a keyPath from the selection in another NSArrayController (otherAc.selection.detailsOfMaster). This is the usual way to implement a Master-Detail relationship.

I want to variably change the key path at runtime, using other controls. This way, I sould return a content set that includes several other content sets, which is all advanced and beyond Interface Builder.

To achieve this, I think I should bind the Content Set to my AppDelegate instead. I have tried to do this, but don't know what methods to implement. If I just create the KVC methods (objectSet, setObjectSet), then I can provide a Content Set for the Array Controller in the contentSet method.

However, I don't think I'm binding this properly, because it doesn't "refresh". I'm new to binding; what do I need to implement to properly update the Content Set when other things, like the selection in the master NSArrayController, changes?

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

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

发布评论

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

评论(1

陪我终i 2024-09-05 01:15:55

但是,我认为我没有正确绑定它,因为它不会“刷新”。

这通常意味着您直接分配给实例变量,而不是使用 符合 KVC 的访问器方法,也不发布 KVO 通知。

一般的解决方案是为属性创建访问器方法,然后在任何地方使用它们,包括在该类内部,但在其 initdealloc 方法中除外。

However, I don't think I'm binding this properly, because it doesn't "refresh".

This most often means you are assigning directly to the instance variable, not using KVC-compliant accessor methods nor posting KVO notifications.

The general solution is to create accessor methods for the property and then use them everywhere, including inside that class, except in its init and dealloc methods.

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