views:

1312

answers:

1

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

+9  A: 

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

Peter Hosey
Perfect, thanks.Why does passing nil work? I tried that message with just about every object I could think of…
Rich Catalano
As the NSOutlineView documentation explains, handing it nil as the item tells it to expand all root items.
Peter Hosey