Search code examples
macoscocoaanimationnsoutlineview

NSOutlineView: 'outlineView: heightOfRowByItem:' vs. animating row height


I have NSOutlineView with rows of variable (in runtime) height. It's simple to change the height immediately with outlineView: heightOfRowByItem: method in delegate. But I want to animate row height like during expanding/collapsing animation.

How to do this?


Solution

  • On your NSOutlineView call noteHeightOfRowsWithIndexesChanged: like:

    // index set with all rows that did change height
    NSIndexSet *rows = [NSIndexSet indexSetWithIndex:1];
    [self.outlineView noteHeightOfRowsWithIndexesChanged:rows];
    

    This will animate the rows to the new height as returned by the outlineView:heightOfRowByItem: delegate method.

    From the documentation:

    For View-based tables, this method will animate.
    [...]
    For cell based tables, this method normally doesn't animate. However, it will animate if you call it inside a beginUpdates/endUpdates block.