如何获取 NSOutlineView 可见行的索引?
如何获取 NSOutlineView 可见行的索引? 我需要知道哪个级别和哪些行可见。
[编辑] 我实际上正在寻找的是一个相当于 CocoaTouch/UITableView 的 NSOutlineView - (NSArray *)indexPathsForVisibleRows
How can you get a indexes of visible rows for an NSOutlineView?
I need to know which level and which rows are visible.
[EDIT]
What I'm actually looking for is an NSOutlineView equivalent to CocoaTouch/UITableView - (NSArray *)indexPathsForVisibleRows
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以执行以下操作:
在范围中,您将获得第一个可见单元格的位置,在长度中显示单元格的数量,以便您可以知道可见单元格的索引。
you can do the following:
in the range you will get the location as the first visible cell and in the length the amount of cells are shown so you can know the index of the visible cells.
NSOutlineView
是NSTableView
子类。因此-rowsInRect:
可以与-visibleRect
(来自NSView
)结合使用。使用-levelForRow:
确定级别。NSOutlineView
is anNSTableView
subclass. Therefore-rowsInRect:
can be combined with-visibleRect
(fromNSView
). Use-levelForRow:
to determine the level.我更改了数据源以返回大纲视图的 NSIndexPath:child:ofItem:。
这样我可以使用 [outlineview rowAtPoint:point] (和类似的)来获取 NSIndexPath。
此更改要求我创建一组这些索引路径,以便在我不需要它们之前它们不会被释放。此外,通常需要模型对象的所有其他代码现在都需要从索引路径查找模型对象。就我而言,这是有效的。
I changed my datasource to return an NSIndexPath for outlineView:child:ofItem:.
This way I could use [outlineview rowAtPoint:point] (and similar) to get the NSIndexPath.
This change required me to make a set of these indexPaths so they wouldn't get released until I don't need them. Also, all the other code which normally expected a model object now needs to lookup the model object from the index path. In my case this was efficient.
在 Swift 3 中:
In Swift 3: