macOS TableView dynamic row height?

Environment is macOS Monterey Xcode 13.

Is there a way to change the behavior of a macOS NSTableView to have the row height change based on the contents of a column. As an example when populating the column data and the width of the content exceeds the width of the column to have the content wrap to an additional line, which of course the row height would have to change then as well.

If so, how can this be done?

Thanks

Answered by DTS Engineer in 724639022

It should be to specify usesAutomaticRowHeights on your table view:

https://developer.apple.com/documentation/appkit/nstableview/2870126-usesautomaticrowheights

You can also do this in the IB canvas by setting "Row Size Style" in the table view attributes to "Automatic (Auto Layout)".

Note that you should also specify a reasonable rowHeight value, since that's used for rows whose sizes have not yet been calculated. You also should make sure that your cell contents are properly configured to be able to wrap. For example, you should configure text fields to wrap rather than truncate to a single line.

Accepted Answer

It should be to specify usesAutomaticRowHeights on your table view:

https://developer.apple.com/documentation/appkit/nstableview/2870126-usesautomaticrowheights

You can also do this in the IB canvas by setting "Row Size Style" in the table view attributes to "Automatic (Auto Layout)".

Note that you should also specify a reasonable rowHeight value, since that's used for rows whose sizes have not yet been calculated. You also should make sure that your cell contents are properly configured to be able to wrap. For example, you should configure text fields to wrap rather than truncate to a single line.

macOS TableView dynamic row height?
 
 
Q