Question

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

Was it helpful?

Solution

I'd like to expand every node in my -awakeFromNib().

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 the expandItem: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.)

I'd also like to programatically select the first child of the first node at the same time.

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].

OTHER TIPS

If you're loading from a datasource,

dispatch_async(dispatch_get_main_queue(), ^{
  [self.outlineView expandItem:root expandChildren:YES];
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top