Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the height of an NSTableCellView that uses autolayout

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.

like image 822
titaniumdecoy Avatar asked Mar 08 '14 01:03

titaniumdecoy


1 Answers

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.

like image 67
goetz Avatar answered Sep 20 '22 05:09

goetz