让我说我在awakeFromNib中的表中加载了100行:,现在我想在垂直滚动器触及底部时调用方法。任何人都可以让我知道如何处理NSScroller触及底部并在发生这种情况时调用方法的事件。
答案 0 :(得分: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];
}
答案 1 :(得分:0)
您可以通过检查tableView.enclosingScrollView.verticalScroller?.floatValue == 1来检测底部的滚动视图,因为垂直滚动器的floatValue在0到1之间变化。