将基于视图的NSOutlineView绑定到Core Data [英] Binding view-based NSOutlineView to Core Data

查看:189
本文介绍了将基于视图的NSOutlineView绑定到Core Data的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的Mac应用程序中实现新的基于视图的OutlineView作为源列表。我不能得到显示的值,所以我从Core Data应用程序模板做了一个小测试应用程序,也无法使其正常工作。



我在我的数据模型中定义了两个简单的类;让我们称他们为父和孩子。 父级有一个属性,名称和单个关系子级。 名称是可选字符串,是与的可选对多关系。 具有与相反的名称属性和一个父关系。我为这两种类型生成了自定义类,并在中为写了一个存根,返回 nil p>

我将源列表从对象库拖动到我的XIB,并放在树控制器中。树控制器的键路径设置为children,它处于实体名称模式,将Parent作为实体名称,准备内容检查,并将其管理对象上下文设置为应用程序委托的上下文。树控制器是大纲视图的数据源,我使用objectValue.name键路径将数据单元格的文本视图绑定到表格单元格视图。



in -applicationDidFinishLaunching:我创建两个实例,一个包含,并分配名称属性。



src =https://i.stack.imgur.com/0E4D8.pngalt =无文本>



现在, ,我得到显示在源列表中的行,但文本字段是空的,即使他们绑定。我不认为我需要做任何其他事情,因为我使用绑定,我相当肯定绑定到 objectValue 属性是正确的事情。出现了什么问题?



如果需要,我可以提供更多的细节,但是我确信它覆盖了我做的一切。

解决方案

哇,就像我从两个星期前来问这个问题。



无论如何,像我一样,问题是,

基于视图的 NSOutlineViews ,您需要实现

   - (NSView *)outlineView:(NSOutlineView *)outlineView 
viewForTableColumn:(NSTableColumn *)tableColumn
item:

委托方法,并返回 NSTableCellView

或者他们只是给你一个空行。最简单的方法是调用

  [outlineView makeViewWithIdentifier:@MyCellowner:self] 

替换 MyCell 项目标识符

在您的 NSTableCellView 的身份检查器中。


I'm trying to implement the new view-based OutlineView as a source list in my Mac app. I can't get values to display, though, so I made a small test app from the Core Data app template, and can't get it working right in there, either.

I defined two simple classes in my data model; let's call them "Parent" and "Child". Parent has a single Attribute, "name", and a single relationship, "children". name is an optional string, and children is an optional to-many relationship to Child. Child has the same "name" attribute and a to-one "parent" relationship that is the inverse of children. I generated custom classes for both of those, and wrote a stub in Child for children that returns nil.

I dragged a Source List from the Object library onto my XIB, and dropped in a Tree Controller. The Tree Controller's Children Key Path is set to "children", it's in Entity Name mode, with "Parent" as the Entity Name, Prepares Content checked, and its Managed Object Context set to the app delegate's context. The Tree Controller is the data source of the outline view, and I bound the data cell's text view to Table Cell View, with the "objectValue.name" key path.

in -applicationDidFinishLaunching: I create two Parent instances, one with a Child, and assign the name property of every object.

The actual problem

Now, with that setup out of the way, I get rows showing up in the source list, but the text fields are empty, even though they're bound. I don't think I should need to do anything else, since I'm using bindings, and I'm fairly certain binding to the objectValue property is the right thing. What's going wrong?

I can provide more detail if necessary, but I'm pretty sure that covers everything I did.

解决方案

Wow, it's like me from two weeks ago is asking this question.

Anyway, if you're anything like me, the problem is that,
for view-based NSOutlineViews, you need to implement the

- (NSView *)outlineView:(NSOutlineView *)outlineView
     viewForTableColumn:(NSTableColumn *)tableColumn
                   item:(id)item;

delegate method and return the NSTableCellView you set up,
or they'll just give you a blank line. The easiest way to do this is to just call

[outlineView makeViewWithIdentifier:@"MyCell" owner:self]

replacing MyCell with whatever you typed in as the "User Interface Item Identifier"
in the Identity Inspector for your NSTableCellView.

这篇关于将基于视图的NSOutlineView绑定到Core Data的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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