2012-08-22 2 views
9

동적 뷰가있는 뷰 기반 NSTableView은 테이블 뷰 크기가 변경 될 때 행의 크기가 조정되지 않습니다. 행 높이가 테이블 뷰의 너비에서 파생 될 때 문제가됩니다 (열을 채우고 줄 크기를 확장하는 텍스트 블록을 생각하십시오). 뷰 기반 NSTableView에서 행의 크기를 올바르게 조정

가 나는 크기를 변경할 때마다 1 행의 크기를 조정 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과 관련되어 있지만 테이블보기의 크기 변경에 응답하는 데 더 중점을 둡니다.

답변

11

방금이 정확한 문제를 해결했습니다. 내가 한 일은 스크롤 뷰의 내용보기

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollViewContentBoundsDidChange:) name:NSViewBoundsDidChangeNotification object:self.scrollView.contentView]; 

의 NSViewBoundsDidChangeNotification을 모니터링하고 핸들러에서, 가시 행을 얻을 noteHeightOfRowsWithIndexesChange를 호출했다 :. 나는이 일을하면서 뷰의이 신속하게 수행 할 수있는 테이블

- (void)scrollViewContentBoundsDidChange:(NSNotification*)notification 
{ 
    NSRange visibleRows = [self.tableView rowsInRect:self.scrollView.contentView.bounds]; 
    [NSAnimationContext beginGrouping]; 
    [[NSAnimationContext currentContext] setDuration:0]; 
    [self.tableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:visibleRows]]; 
    [NSAnimationContext endGrouping]; 
} 

에 와서 사용자가 행 크기 조정시 흔들 보지 않도록 애니메이션을 사용하지 그래서 테이블 좋게 스크롤하지만 나를 위해 잘 작동합니다.

+0

나를 위해 사용자가 크기 조정을 완료하고 행 높이를 다시 조정할 때까지 기다렸습니다. – adib

+1

분명히 스크롤 뷰 내용보기는 '[self.scrollView.contentView setPostsBoundsChangedNotifications : YES]를 호출 한 후에도 변경 알림을 게시하지 않습니다. – adib

+1

NSViewFrameDidChangNotification은 NSViewFrameDidChangNotification에 대한 라이브 크기 조정을 위해 –