4

NSTableView is what I am using to display millions of data, which I can not get in response due to time out.

So what I decided to get response in pages say 1-100 then 101-200 etc.

So my problem starts here, how can I know that I have reached to the end of tableView or the cell is visible say 100th row?

I dont want to implement Load More.. kind of button etc.

After this I will send a new response with new range.


Here is what I have tried so far:

Tried to track the scrollView and get next set of data by a service call.

*It works with old mouse but it failed with swipe.

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • oops sorry, guess I misunderstood your question – Eugene Jun 21 '13 at 13:00
  • You shouldn't worry about what row you have reached. When you implement data source you'll get asked for the proper rows, according to what rows are visible. Is enough that you put them in some cache. For example you get asked for row 50, if the row is in the cache you just return it's value, otherwise you fetch rows from 0 to 100 ([N-50,N+50]) and put them in the cache. – Ramy Al Zuhouri Jun 21 '13 at 13:08
  • @RamyAlZuhouri: I dont want unneccessary fetching of data. I want data to be fetched only when last row is visible. See this very similar to Facebook and all other sites. Also I dont want to implement `Load More..` kind of button etc – Anoop Vaidya Jun 21 '13 at 13:18
  • So your goal is a sort of “infinite scrolling” UI, where new rows are brought in to the model upon reaching the end of the view? – Peter Hosey Jun 23 '13 at 17:39
  • @AnoopVaidya Any suggestions for http://stackoverflow.com/questions/21795083/detect-last-visible-nscollectionview-item-prototype?noredirect=1#comment32980829_21795083 – user88975 Feb 15 '14 at 11:32

1 Answers1

4

Maybe you can determine the last visible row after a scroll, I've a subclassed NSTableView with this method

@interface MyTableView : NSTableView
- (NSInteger)lastVisibleRow;
@end


@implementation MyTableView
    - (NSInteger)lastVisibleRow {
        NSRect bounds = [[self superview] bounds];
        bounds.origin.y += bounds.size.height - 1;
        return [self rowAtPoint:bounds.origin];
    }

@end
dafi
  • 3,492
  • 2
  • 28
  • 51
  • Great ! This helped me. But I need to add observer to tableView scroll ers right ? `NSViewBoundsDidChangeNotification` ? Then in the notification I am checking to see if `lastVisible row >= rowcount` and then reloading more data. – GoodSp33d Nov 25 '13 at 15:18