是否可以将NSTreeController绑定到NSOutlineViewDataSource? [英] Is it possible to bind an NSTreeController to an NSOutlineViewDataSource?

查看:433
本文介绍了是否可以将NSTreeController绑定到NSOutlineViewDataSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些层次数据模型,我想在一个NSOutlineView。我将树控制器绑定到大纲视图以提供数据并处理选择和绑定到其他视图。

I have some hierarchical data model that I'd like to present in an NSOutlineView. I'm binding a tree controller to the outline view to provide data and to handle selection and binding to other views.

但是,我只想显示我的模型中的数据的一部分添加到大纲视图。 (我的层次结构中的每个对象都有一个子对象数组,但我只想让其中一些子对象显示为树中节点的子节点。)我希望我可以将一个过滤谓词附加到树控件,但似乎NSOutlineView不支持过滤谓词。

However, I only want to show only part of the data in my model to the outline view. (Each object in my hierarchy has an array of child objects, but I'd only like some of these child objects to appear as child nodes of the node in the tree.) I wish I could just attach a filter predicate to the tree controller, but it seems that NSOutlineView doesn't support filter predicates.

我认为这个设计需要一个NSOutlineViewDataSource过滤我的数据模型,绑定到数据源和大纲视图的NSTreeController。但是,树控制器(内容数组,内容对象,内容集等)中的绑定出口都不适合绑定数据源。

I think that this design requires an NSOutlineViewDataSource to filter my data model, and an NSTreeController bound to the data source and the outline view. However, none of the binding outlets in the tree controller (Content Array, Content Object, Content Set, etc.) seems appropriate for binding a data source.

任何想法?提前感谢...

Any ideas? Thanks in advance...

推荐答案

一般来说,NS [Outline | Table] ViewDataSource和Cocoa Bindings是一个 选择。

In general, NS[Outline|Table]ViewDataSource and Cocoa Bindings is an "either/or" choice. Mixing the approaches, while perhaps not strictly impossible, will likely lead to unpredictable results.

您提到将过滤谓词绑定到大纲视图本身中,但不一定非得不可能

You mention binding a filter predicate to the Outline View itself and not to specific nodes, so I surmise that one filter predicate for all nodes might be "good enough." If that's the case, then one solution to this would be to expose a second children-vending property on your model, maybe filteredChildren, and tell the NSOutlineView to use that to access children instead of the your default/complete children-vending property. If you need functionality like drag reordering, this approach might prove to be non-trivial, but it should be easy to explore this approach regardless.

如果你需要一个不同的过滤器对于每个节点,或者如果过滤器动态更改,这个任务可能已经跨越到一个case是一个很好的候选人执行NSOutlineViewDataSource(和一个糟糕的候选人使用Cocoa Bindings。)

If you need a different filter for each node, or if the filter changes dynamically, this task would likely have crossed over into being a case that was a good candidate for implementing NSOutlineViewDataSource (and a poor candidate for using Cocoa Bindings.)

这篇关于是否可以将NSTreeController绑定到NSOutlineViewDataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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