在单个 NSOutlineView 中可视化不同的实体

发布于 2024-12-05 00:59:44 字数 845 浏览 0 评论 0原文

假设我正在使用核心数据为动物创建参考应用程序。每个动物生活在一个栖息地中,并且有一个分类。一个分类可能有子分类(使用简单的一对多父/子关系在核心数据中建模)。

我想使用单个 NSOutlineView 可视化所有三个实体 - HabitatsClassificationsAnimals 。例如,它可能看起来像这样:

v Animals
   Cat
   Parrot
   Seagull
   Toucan Sam
v Habitats
   Cereal Box
   Coast
   Jungle
   Living Room
v Classifications
   Mammal
   v Bird
      Tropical Bird
      Fictional Bird

我可以使用 NSTreeController 和 Cocoa Bindings 来非常轻松地可视化单个实体(具有分层结构),例如 Classifications。 (并且已经这样做了。)但是,这需要将表列绑定到单个同质“类型”。

我想我可以创建一个自定义类,其中包含对我的 NSTreeController 对象的引用,然后将表列绑定到该自定义类中的方法(执行各种排列对象的聚合) 到我自己的 NSSet 中)。但是,Xcode 似乎不想让我绑定到它(显示 (!) 并拒绝让我在绑定检查器中设置控制器键)。

如何在单个 NSOutlineView 中可视化多个实体?

Let's say that I am creating reference app, using Core Data, for animals. Each Animal lives in a Habitat, and has a Classification. A Classification might have sub-Classifications (modelled in Core Data using a simple one-to-many parent/children relationship.).

I would like to visualize all three Entities -- Habitats, Classifications, and Animals -- using a single NSOutlineView. For example, it might look like this:

v Animals
   Cat
   Parrot
   Seagull
   Toucan Sam
v Habitats
   Cereal Box
   Coast
   Jungle
   Living Room
v Classifications
   Mammal
   v Bird
      Tropical Bird
      Fictional Bird

I can use an NSTreeController and Cocoa Bindings to visualize a single Entity (with hierarchical structure) like Classifications quite easily. (And have done so already.) However, this requires the table column to be bound to a single homogenous "type".

I thought I could create a custom class that contains references to my NSTreeController objects, and then have the table column bind to a method in this custom class (performing a kind of aggregation of the various arrangedObjects into an NSSet myself). However, Xcode doesn't seem to want to let me bind to it (displays a (!) and refuses to let me set the Controller Key in the Bindings inspector).

How can I visualize more than one Entity in a single NSOutlineView?

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

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

发布评论

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

评论(1

给我一枪 2024-12-12 00:59:44

您有两个选择:

  1. 使用 HabitatsClassificationsAnimals 的超级实体,然后将 NSTreeController 键入该超级实体。
  2. 编写一个自定义控制器。

对于(1),树控制器正在寻找父子关系。对于大纲树中显示的所有对象,该关系的键名称必须相同。如果您提供具有 eh 键名称的超级实体,则它的所有子实体都将响应树控制器。

然而,你真正的问题是概念性的。您将实体与托管对象混淆,并尝试创建一个大纲,该大纲具有表示实体的层次结构级别和表示托管对象的其他级别。

v EntityName="Animals"
   anAnimalObject.name="cat"
   anAnimalObject.name="Parrot"
   anAnimalObject.name="Seagull"
v EntityName="Habitats"
   aHabitatObject.name="Cereal Box"
   aHabitatObject.name="Coast"
v EntityName="Classifications"
   aClassificationObject.name="Mammal"
   v aClassificationObject.name="Bird"
      aClassificationObject.name.subclassifications.anotherClassificationObject.name="Tropical Bird"

如果您使用绑定,您的数据模型在某些方面看起来就像 UI。您的数据模型看起来不是这样的。数据模型不会对实体本身进行递归建模,因此您不能单独使用数据模型来显示实体或显示按实体分组和排列的对象。

您将需要编写一个自定义控制器,该控制器将包含代码来检查每个对象的实体以及该对象在大纲层次结构中正确位置的位置。您将需要三个单独的提取,每个实体一个。

You have two options:

  1. Use a superentity for Habitats, Classifications, and Animals and then key the the NSTreeController to the superentity.
  2. Write a custom controller.

For (1), a tree controller is looking for a parent-child relationship. The key-name of that relationship has to be the same for all object displayed in the outline tree. If you provide a superentity with eh key-name, all it's subentities will respond to the tree controller.

However, your real problem here is conceptual. You are confusing entities with managed objects and trying to create an outline that has one level of the hierarchy representing entities and other levels representing managed objects.

v EntityName="Animals"
   anAnimalObject.name="cat"
   anAnimalObject.name="Parrot"
   anAnimalObject.name="Seagull"
v EntityName="Habitats"
   aHabitatObject.name="Cereal Box"
   aHabitatObject.name="Coast"
v EntityName="Classifications"
   aClassificationObject.name="Mammal"
   v aClassificationObject.name="Bird"
      aClassificationObject.name.subclassifications.anotherClassificationObject.name="Tropical Bird"

If you use bindings, your data model look like the UI in some respect. Your data model doesn't look like this. The data model does not recursively model the entities themselves so you can't use the data model alone to display the entities or to display objects grouped and arranged by entity.

You will need to write a custom controller that will have code to check for he entity of each object and the position the object in the correct place in the outline hierarchy. You will need three separate fetches, one for each entity.

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