在我的应用程序中,我有一个 NSOutlineView,它从 NSTreeController 获取数据,而 NSTreeController 又从核心数据模型获取数据。
我现在想做的是将组标题添加到大纲视图中,也许还添加一些附加行——显然这些东西应该存在于模型之外并成为视图的一部分。但是,尽管我对此绞尽脑汁,但我想不出任何方法可以让大纲视图在不修改底层模型的情况下显示这些内容,这显然是一个很大的禁忌。
非常感谢您的帮助。我觉得我在这里错过了一些明显的东西......
In my app, I have an NSOutlineView
that gets its data from a NSTreeController
-- which in turn gets it from the Core Data model.
What I would like to do now is to add group headings and maybe some additional rows to the outline view -- obviously things that should exist outside of the model and be part of the view. But, as much as I scratch my head over this, I can't think of any way to make the outline view display these things without modifying the underlying model, which is obviously a big no-no.
Your help is very appreciated. I feel like I am missing something obvious here...
发布评论
评论(1)
您在这里要做的是编写一个自定义的 NSTreeController 子类。这就是为什么这是您想要进行更改的完美位置的原因:
幸运的是,Cocoa 中的控制器类非常强大,同时也非常简单。对你来说,覆盖
-arrangedObjects
方法。重用默认实现,因为它做了很多有用的事情,例如应用谓词或排序。其外观如下:返回的对象属于类
NSTreeNode
- 请参阅有关如何进行修改的文档。What you would do here is to write a custom
NSTreeController
subclass. Here is why this is the perfect place for the changes you want to do:Luckily, the Controller classes in Cocoa are very powerful and very simple at the same this. For you it should be enough to override the
-arrangedObjects
method. Re-use the default implementation, as it does a lot of useful things like applying predicates or sorting. Here's how this could look like:The returned object is of the class
NSTreeNode
- see the documentation on how to do modifications.