Search code examples
swiftmacosappkit

Expanding Rows in NSTableView


Is it possible to collapse/expand rows in an NSTableView in the same way as an NSOutlineView?

I would like to mimic the behaviour of NSOutlineView in NSTableView.


Solution

  • You can hide rows with NSTableView.hideRows(at indexes: IndexSet, withAnimation: NSTableView.AnimationOptions = []).

    You can show rows with NSTableView.unhideRows(at indexes: IndexSet, withAnimation rowAnimation: NSTableView.AnimationOptions = []).

    You can get the indexes of hidden rows with NSTableView.hiddenRowIndexes.

    Note that hiding and showing rows fire certain NSTableViewDelegate methods. See the documentation for details.