How to determine if a user scrolls to the end of an NSTableView

I have an NSTableView, and I would like to know when the user scrolls to the bottom, so I can perform the action. Not quite sure how to do this?

UPDATE: This is how I calculate the bottom of the table:

-(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!"); } } 
+6
objective-c cocoa nstableview macos nsscrollview
source share
2 answers

You can add yourself as an observer (in the sense of NSNotificationCenter, and not in the sense of KVO / Bindings) NSViewBoundsDidChangeNotification from the -enclosingScrollView -contentView table and react based on the visible rectangle as needed.

Update

Do it somewhere (maybe -awakeFromNib):

 // 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]; 

Put this somewhere useful:

 - (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification { if ([aNotification object] == [[tableView enclosingScrollView] contentView]) [self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe]; } 

Essentially, you want to view the scroll view -documentVisibleRect to see if the bottom pairs of pixels can be seen. Remember to consider the possibility of viewing with inverted coordinate systems - "inverted views" - in the View Programming Guide .

+14
source share

Regarding your update: for some reason I have var currentPosition = CGRectGetMaxY ([scrollView visibleRect]); always the same value, I found it better to use the NSClipView borders:

 NSClipView *clipView = ...; NSRect newClipBounds = [clipView bounds]; CGFloat currentPosition = newClipBounds.origin.y + newClipBounds.size.height; 
0
source share

All Articles