给定模型对象,如何在 NSTreeController 中找到索引路径?
给定 NSTreeController 表示的模型对象,如何在树中找到它们的索引路径并随后选择它们?这似乎是一个非常明显的问题,但我似乎找不到任何参考。有什么想法吗?
Given model objects that NSTreeController
represents, how do you find their index paths in the tree and subsequently select them? This seems to be a blindingly obvious problem, but I can't seem to find any reference to it. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有“简单”的方法,您必须遍历树节点并找到匹配的索引路径,例如:
Objective-C:
Category
Swift:
扩展
There's no "easy" way, you have to walk the tree nodes and find a matching index path, something like:
Objective-C:
Category
Swift:
Extension
为什么不使用 NSOutlineView 来获取这样的父项:
这将输出: ./item1/item2/item3/...
我假设您正在此处查找文件路径,但您可以根据数据源进行调整代表。
Why not use the NSOutlineView to get the parent items like this:
This will output: ./item1/item2/item3/...
I'm assuming you are looking for a file path here but you can adjust for whatever your data source may represent.