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