Scroll an NSTableView so that a row is centered <p>I want to programmatically scroll an NSTableView so that a particular row is centered. It's simple to scroll the NSTableView so that a particular row is visible:</p> <pre><code>[theTableView scrollRowToVisible:pos]; </code></pre> <p>However, usually the row in question is at the bottom of the visible area, whereas I'd like it to be roughly in the center.</p> <p>Another stupid approach is to scroll a few rows beyond the one I want to be visible, e.g., something like:</p> <pre><code> // pos = index of desired row // numRows = number of rows in the table NSRect visibleRect = [resultsTableView visibleRect]; NSRange visibleRange = [resultsTableView rowsInRect:visibleRect]; NSUInteger offset = visibleRange.length/2; NSUInteger i; if (pos + offset &gt;= numRows) i = numRows - 1; else if (pos &lt; visibleRange.length) i = pos; else i = pos + offset; [resultsTableView scrollRowToVisible:i]; </code></pre> <p>This works if all rows are exactly the same height, but I am interested in making rows with different heights.</p> <p>Is there a better, perhaps more direct, way to do this? For example, I have noticed that the NSTableView is wrapped in an NSScrollView.... (The table was made using Interface Builder.)</p> <p>Thanks!</p>