Note that there are some explanatory texts on larger screens.

plurals
  1. POCorrectly resizing rows on view-based NSTableView
    text
    copied!<p>A view-based <code>NSTableView</code> with rows that have dynamic heights doesn't resize its rows when the table view size is changed. This is a problem when the row height is derived from the table view's width (think text blocks that fills a column and wraps thus extending the row size).</p> <p>I've been trying to get <code>NSTableView</code> to resize its rows whenever it changed size but have experienced little success:</p> <ul> <li>If I resize only the visible rows by querying <code>enumerateAvailableRowViewsUsingBlock:</code>, some of the non-visible rows doesn't get resized and thus were shown with the old height when the user scrolls and reveal these rows.</li> <li>If I resize all rows it becomes noticeably slow when there are a lot of rows (about 1 second delay after each window resize for 1000 rows in my 1.8Ghz i7 MacBook Air). </li> </ul> <p>Anybody can help?</p> <p>This is where I detect the table view size change - in the table view's delegate:</p> <pre class="lang-c prettyprint-override"><code>- (void)tableViewColumnDidResize:(NSNotification *)aNotification { NSTableView* aTableView = aNotification.object; if (aTableView == self.messagesView) { // coalesce all column resize notifications into one -- calls messagesViewDidResize: below NSNotification* repostNotification = [NSNotification notificationWithName:BSMessageViewDidResizeNotification object:self]; [[NSNotificationQueue defaultQueue] enqueueNotification:repostNotification postingStyle:NSPostWhenIdle]; } } </code></pre> <p>Whereas the following is the handler of the notification posted above, where the visible rows get resized:</p> <pre class="lang-c prettyprint-override"><code>-(void)messagesViewDidResize:(NSNotification *)notification { NSTableView* messagesView = self.messagesView; NSMutableIndexSet* visibleIndexes = [NSMutableIndexSet new]; [messagesView enumerateAvailableRowViewsUsingBlock:^(NSTableRowView *rowView, NSInteger row) { if (row &gt;= 0) { [visibleIndexes addIndex:row]; } }]; [messagesView noteHeightOfRowsWithIndexesChanged:visibleIndexes]; } </code></pre> <p>The alternative implementation that resizes all rows looks like this:</p> <pre class="lang-c prettyprint-override"><code>-(void)messagesViewDidResize:(NSNotification *)notification { NSTableView* messagesView = self.messagesView; NSIndexSet indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,messagesView.numberOfRows)]; [messagesView noteHeightOfRowsWithIndexesChanged:indexes]; } </code></pre> <p>Note: This question is somewhat related to <a href="https://stackoverflow.com/questions/7504546/view-based-nstableview-with-rows-that-have-dynamic-heights">View-based NSTableView with rows that have dynamic heights</a> but is more focused towards responding to the table view's size change.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload