NSOutlineView 中的非唯一项
根据 Apple 的文档,NSOutlineView
要求视图中的每个项目都是唯一的,但是,如果这实际上不符合业务需求?特别是,如何显示类似这样的
Item A
-> Item B
-> Item E
-> Item C
Item D
-> Item B
-> Item E
-> Item F
内容 请注意项目 B 及其子项目如何多次出现在树中。当然,应用程序会进行检查以确保不会发生循环,因此树是有限的。
子类化 NSOutlineView
有帮助吗?或者是否需要创建一个全新的视图类?
According to Apple's documentation, NSOutlineView
requires each item in the view to be unique, however, what if this doesn't actually fit the business requirement? In particular, how do you display something like this
Item A
-> Item B
-> Item E
-> Item C
Item D
-> Item B
-> Item E
-> Item F
Note how Item B, as well as its children, appear in the tree multiple times. Of course, the application does checks to make sure no circular loop can happen so the tree is finite.
Would subclassing the NSOutlineView
help? Or would a completely new view class need to be created?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 NSIndexPath 对象作为大纲视图中的项目。例如,索引路径 (0, 0) 将引用项目 A 的项目 B,而索引路径 (1, 0) 将引用项目 D 的项目
B。您需要实现一个数据源。
您的数据源方法将需要使用索引路径从模型中获取相关的真实模型对象。我建议创建一个方法来执行此操作,并从所有数据源方法中使用该方法。
此外,您还需要正确处理删除对象:如果删除模型数组中间的对象,则必须删除末尾的索引路径,而不是中间的索引路径,并告诉视图重新加载之间的所有项目(索引路径)。
You could use NSIndexPath objects as the items in the outline view. For example, index path (0, 0) would refer to Item B of Item A, while index path (1, 0) would refer to Item B of Item D.
You won't be able to use Bindings; you'll need to implement a data source.
Your data source methods will need to get the relevant real model object from your model using the index path. I recommend making a method that does that and using that method from all of the data source methods.
Also, you'll need to correctly handle deleting objects: If you delete an object in the middle of the model array, you have to delete the index path at the end, not the one in the middle, and tell the view to reload all the items (index paths) in between.