0

I have a NSTableview which shows 50 rows currently which is fixed static. Now I want to add a feature into it. I want to add a more 50 rows to the table when user reach to the last row of the NSTableView. I mean currently I am showing fixed 50 rows in the application.

But now I want to add 50 more rows whenever user reaches to the last row of previous NsTableview.

Please give me any suggestions or any sample code to achieve my motive. Thanks in advance.

What i have done is(This code does not work with row selected(Down key pressed), and does not load new rows) -

-(void)awakeFromNib{

    for(int i=0;i<25;i++)
        [_list addObject:[[Person alloc] init]];
    [_tableView reloadData];

        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(scrollViewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[_tableView enclosingScrollView] contentView]];

}

    -(void) doSomething{
        Person *p = [[Person alloc] init];
        static int i =1;
        NSString *string = [NSString stringWithFormat:@"John%i",i];
        [p setName:string];
        for(int i=0;i<25;i++)
            [_list addObject:p];
// Need to use reloadDataForRowIndexes:columnIndexes: anyone please help me with this.
            [_tableView reloadData];

        i++;

    }
- (void)scrollViewDidScroll:(NSNotification *)notification {

    NSScrollView *scrollView = [notification object];
    // Test if bottom of content view is reached.
    CGFloat currentPosition = CGRectGetMaxY([scrollView visibleRect]);
    CGFloat tableViewHeight = [self.tableView bounds].size.height;

    if (currentPosition  > tableViewHeight) {
        // YOUR ACTION

        [self doSomething];


     }
john fedric
  • 167
  • 1
  • 11
  • Why not making tableView with max rows from the beginning? If You're using reusable cells It won't have big impact on Your memory footprint. – Mateusz Szlosek Aug 29 '14 at 11:15
  • @Mateusz Szlosek I am designing an app in which it is one of the requirement.. – john fedric Aug 29 '14 at 13:47
  • 1
    Perhaps this [answer](http://stackoverflow.com/questions/4959544/how-to-determine-if-a-user-has-scrolled-to-the-end-of-an-nstableview) might be of use to you... – GoodSp33d Aug 30 '14 at 06:55
  • @GoodSp33d Could you help me with using reloadDataForRowIndexes:columnIndexes: and tell me why this code does not work with Down key(Row Selected). – john fedric Aug 30 '14 at 10:43

0 Answers0