2014-08-27 6 views
1

awakeFromNib에서 테이블에 100 개의 행을로드한다고 가정 해 보겠습니다. 이제 수직 스크롤러가 바닥에 닿을 때 메서드를 호출하려고합니다. 아무도 나를 NSScroller 이벤트를 처리하는 방법을 알고 바닥에 충돌이 일어날 때 메서드를 호출 할 수 있습니다.NSTableView에서 수직 NSScroller 아래쪽으로 치기

답변

3
// In awakeFromNib: 
self.scrollView = [self.tableView enclosingScrollView]; 

// Register delegate to the scrollView content View: 
// This will send notification whenever scrollView content view visible frame changes. 
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(scrollViewDidScroll:) name:NSViewBoundsDidChangeNotification object:self.scrollView.contentView]; 

// This Method is called when content view frame changed 
- (void)scrollViewDidScroll:(NSNotification *)notification { 
    NSScrollView *scrollView = self.scrollView; 
    // Test if bottom of content view is reached. 
    CGFloat currentPosition = CGRectGetMaxY([scrollView visibleRect]); 
    CGFloat contentHeight = [self.tableView bounds].size.height - 5; 

    if (currentPosition > contentHeight - 2.0) { 
     // YOUR ACTION 
    } 
} 
// Remove observer 
- (void)dealloc { 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
} 
+0

NSScrollView에서 NSClipView 개체를 잡는 이유 * scrollView = [알림 개체]; ?? –

+0

대신 속성을 사용하도록 코드가 업데이트되었습니다. – Krzysztof

+0

나는 코코아에서 조금 새로운데, 전체 코드를 설명해 주 시겠어요 .. –