2011-02-10 3 views
6

NSTableView가 있는데 사용자가 아래로 스크롤 한 것을 알고 싶습니다. 그러면 작업을 수행 할 수 있습니다. 이 문제를 어떻게 해결할 지 잘 모르십니까? UPDATE사용자가 NSTableView 끝까지 스크롤했는지 확인하는 방법

:

-(void)tableViewDidScroll:(CPNotification) notification 
{ 
    var scrollView = [notification object]; 
    var currentPosition = CGRectGetMaxY([scrollView visibleRect]); 
    var tableViewHeight = [messagesTableView bounds].size.height - 100; 

    //console.log("TableView Height: " + tableViewHeight); 
    //console.log("Current Position: " + currentPosition); 

    if (currentPosition > tableViewHeight - 100) 
    { 
     console.log("we're at the bottom!"); 
    } 
} 

답변

14

당신은 (즉, NSNotificationCenter의 의미에서가 아니라 KVO/바인딩 의미) 관찰자로서 자신을 추가 할 수 있습니다 NSViewBoundsDidChangeNotification의에서 : 여기 내가 테이블의 바닥을 계산하고 어떻게 테이블의 -enclosingScrollView의 -content 보이는 직사각형을 기반으로 필요에 따라보고 반응합니다.

업데이트

이 어딘가에 (아마도 -awakeFromNib를) 수행은 :

- (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification 
{ 

if ([aNotification object] == [[tableView enclosingScrollView] contentView]) 
    [self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe]; 

} 

는 기본적으로 사용자가 스크롤 뷰의 -documentVisibleRect보고 검사 할 :

// Configure the scroll view to send frame change notifications 
id clipView = [[tableView enclosingScrollView] contentView]; 
[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(myBoundsChangeNotificationHandler:) 
              name:NSViewBoundsDidChangeNotification 
              object:clipView]; 

도움이 어딘가에 넣어 어쩌면 픽셀의 아래쪽 쌍을 볼 수 있습니다. Views Programming Guide에 설명 된 대칭 좌표계가 적용된 뷰 (뒤집힌 뷰)의 가능성을 고려해야합니다.

+0

당신이 조각을 보여줄 수 : 항상 같은 값은 내가 NSClipView 경계를 사용하는 것이 더 발견했습니다? –

+0

게시물을 업데이트했습니다. –

+0

잘 작동합니다. 하단 픽셀을 볼 수 있는지 계산하는 데 약간의 도움을받을 수 있습니까? –

0

당신의 갱신에 관한 : 내가 = CGRectGetMaxY ([있는 ScrollView visibleRect]) var에 currentPosition이 어떤 이유로 을;

NSClipView *clipView = ...; 
NSRect newClipBounds = [clipView bounds]; 
CGFloat currentPosition = newClipBounds.origin.y + newClipBounds.size.height; 
관련 문제