Search code examples
macoscocoa-touchnsoutlineview

Expand all the items of an NSOutlineView to a level


How can I, on setup, expand all items of an NSOutlineVIew to a determined level? After this the user it's free to expando or collapse all the nodes of the tree.

The data comes from a NSTreeController bound to the view.


Solution

  • This should do it:

    for (NSInteger i = 0; i < outlineView.numberOfRows; i++)
    {
        if ([outlineView levelForRow:i] < depthLimit)
            [outlineView expandItem:[outlineView itemAtRow:i]];
    }