9
具有動態高度的行的基於視圖的NSTableView
不會在更改表視圖大小時調整行的大小。當行高從表視圖的寬度派生時(認爲填充列和換行從而擴展行大小的文本塊),這是一個問題。在基於視圖的NSTableView上正確調整行大小行
我一直試圖讓NSTableView
來調整其行,只要改變它的大小,但經歷過小的成功:
- 如果我通過查詢
enumerateAvailableRowViewsUsingBlock:
,一些非可見的行調整僅可見行不會調整大小,因此當用戶滾動並顯示這些行時,會顯示舊高度。 - 如果我調整所有行的大小,當行數很多時(每個窗口在我的1.8Ghz i7 MacBook Air中調整1000行後大約需要1秒延遲),它會變得非常慢。
有人可以幫忙嗎?
這是我發現表視圖大小的改變 - 在表視圖的委託:
- (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];
}
}
而下面是上面貼的通知,其中可見的行得到調整大小的處理程序:
-(void)messagesViewDidResize:(NSNotification *)notification
{
NSTableView* messagesView = self.messagesView;
NSMutableIndexSet* visibleIndexes = [NSMutableIndexSet new];
[messagesView enumerateAvailableRowViewsUsingBlock:^(NSTableRowView *rowView, NSInteger row) {
if (row >= 0) {
[visibleIndexes addIndex:row];
}
}];
[messagesView noteHeightOfRowsWithIndexesChanged:visibleIndexes];
}
替代實現,調整大小,所有的行看起來是這樣的:
-(void)messagesViewDidResize:(NSNotification *)notification
{
NSTableView* messagesView = self.messagesView;
NSIndexSet indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0,messagesView.numberOfRows)];
[messagesView noteHeightOfRowsWithIndexesChanged:indexes];
}
注意:這個問題與View-based NSTableView with rows that have dynamic heights有些相關,但更注重響應表視圖的大小更改。
對我來說,我一直等到用戶完成調整大小,然後重新調整行高。 – adib
顯然滾動視圖內容視圖不會發布更改通知,即使在調用'[self.scrollView.contentView setPostsBoundsChangedNotifications:YES]' – adib
似乎NSViewFrameDidChangNotification更適合實時調整大小 –