I have a view-based NSTableView
. I positioned the textField
and other elements in an NSTableCellView
in Interface Builder with autolayout. How can I get the height for the cell based on its autolayout parameters?
This answer is the closest I have found to what I am looking for, but it is written for iOS and the systemLayoutSizeFittingSize
method does not exist on NSView
.
You could put the views inside your table cell view into a separate NSView
(let's call this view contentView
). Set Auto Layout constraints for the contentView
so that it aligns to its parent view at the left (leading), top and right (trailing). Make sure the subviews of contentView
resize their parent view. Create an IBOutlet
on that view in your NSTableCellView
subclass. To calculate the height, call fittingSize
on contentView
which should get you the minimal size of your subviews based on the constraints.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With