NSOutlineView - 自动展开所有节点
我有一个绑定到 NSTreeController
的 NSOutlineView
(如果这有影响的话),我想扩展 -awakeFromNib() 中的每个节点
。
我还想同时以编程方式选择第一个节点的第一个子节点。 这些事情对于表格视图来说很简单,但轮廓根本不适合我。
谢谢,
里奇
I've got an NSOutlineView
bound to an NSTreeController
(if that makes a difference), and I'd like to expand every node in my -awakeFromNib()
.
I'd also like to programatically select the first child of the first node at the same time. These sorts of things are simple with table views, but outlines are not cooperating with me at all.
Thanks,
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 Mac OS X 10.5 开始,
[outlineView ExpandItem:nil ExpandChildren:YES]
。在以前版本的 Mac OS X 中,您需要从 0 迭代到行数,使用
[outlineView itemAtRow:row]
获取每行的项目,并将这些项目存储到数组中,然后迭代该数组并将每个项目传递给expandItem:expandChildren:
方法。 (您不能混合使用这两个循环,因为展开一个项目及其所有后代将更改其后续同级项目的行索引;因此,您必须首先收集所有顶级项目,然后在拥有所有项目后展开它们。 )紧接着上面的内容,它将是第 1 行。
大纲视图是一种表视图,因此您将使用 NSTableView 的方法之一:
[outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO]< /代码>。
As of Mac OS X 10.5,
[outlineView expandItem:nil expandChildren:YES]
.In previous versions of Mac OS X, you'll need to iterate from 0 to the number of rows, getting the item for each row using
[outlineView itemAtRow:row]
, and storing those items into an array, then iterate the array and pass each item to theexpandItem:expandChildren:
method. (You can't mix the two loops because expanding an item and all its descendants will change the row indexes of its subsequent siblings; therefore, you must collect all the top-level items first, then expand them once you have all of them.)Immediately after the above, it'll be row 1.
An outline view is a kind of table view, so you'll use one of NSTableView's methods:
[outlineView selectRowIndexes:[NSIndexSet indexSetWithIndex:1] byExtendingSelection:NO]
.如果您从数据源加载,
If you're loading from a datasource,