title: Automatically adjust height of a NSTableView
body: <p>I have asked this question once before, but I'm just not very satisfied with the solution.</p>
  
  <p><a href="https://stackoverflow.com/questions/13445003/automatically-adjust-size-of-nstableview">Automatically adjust size of NSTableView</a></p>
  
  <p>I want to display a <code>NSTableView</code> in a <code>NSPopover</code>, or in a <code>NSWindow</code>.<br />
  Now, the window's size should adjust with the table view.</p>
  
  <p>Just like Xcode does it:</p>
  
  <hr>
  
  <p><img src="https://i.stack.imgur.com/HCYxX.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/wKzMA.png" alt="enter image description here"></p>
  
  <hr>
  
  <p>This is fairly simple with Auto Layout, you can just pin the inner view to the super view.</p>
  
  <p>My problem is, that I can't figure out the optimal height of the table view. 
  The following code enumerates all available rows, but it doesn't return the correct value, because the table view has other elements like separators, and the table head.</p>
  
  <pre><code>- (CGFloat)heightOfAllRows:(NSTableView *)tableView {
      CGFloat __block height;
      [tableView enumerateAvailableRowViewsUsingBlock:^(NSTableRowView *rowView, NSInteger row) {
          // tried it with this one
          height += rowView.frame.size.height;
  
          // and this one
          // height += [self tableView:nil heightOfRow:row];
      }];
  
      return height;
  }
  </code></pre>
  
  <hr>
  
  <h2>1. Question</h2>
  
  <p>How can I fix this? How can I correctly calculate the required height of the table view.</p>
  
  <h2>2. Question</h2>
  
  <p>Where should I run this code?<br />
  I don't want to implement this in a controller, because it's definitely something that the table view should handle itself. <br />
  And I didn't even find any helpful delegate methods.</p>
  
  <p>So I figured best would be if you could subclass <code>NSTableView</code>.<br />
  So my question 2, where to implement it?</p>
  
  <hr>
  
  <h1>Motivation</h1>
  
  <p>Definitely worth a bounty</p>