8

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.

Community
  • 1
  • 1
titaniumdecoy
  • 18,900
  • 17
  • 96
  • 133
  • Conflict - iOS and `NSTableCellView`. Which do you really mean? OS X or `UITableViewCell`? – rmaddy Mar 08 '14 at 01:05
  • @rmaddy I think he means OSX and `NSTableCellView`. He references iOS in a tag (which I edited), but also says "but it is written for iOS" in reference to an answer that would otherwise be helpful. – nhgrif Mar 08 '14 at 01:07
  • Yes thanks, I meant Mac OS X/NSTableCellView. – titaniumdecoy Mar 08 '14 at 01:12

1 Answers1

6

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.

goetz
  • 916
  • 6
  • 14