Search code examples
macosautolayoutnstableview

How to update row heights of NSTableView with usesAutomaticRowHeights = true after column resize?


Since macOS 10.13 we can use NSTableView with automatic row heights, thanks to the new property usesAutomaticRowHeights and of course auto layout. This works quite nicely.

But when the user resizes a column, the calculated heights are no longer correct, and gaps appear in the tableview cells.

Is there a proven way to update the row heights after column resize in this scenario?

I already tried methods like updateConstraintsForSubtreeIfNeeded(), updateConstraints(), setNeedsDisplay(), reloadData() and so on, but nothing works.


Solution

  • If you use NSTextField's in your design, make sure the Desired Width setting of each NSTextField with dynamic height, is set to Automatic. This setting is located in the Size Inspector.

    Changing this resulted in automatic recalculation of the tableview row heights.