Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem detecting if UITableView has scrolled to the bottom

I'm using the following code to detect if I've reached the bottom of a UITableView

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 
    if(self.tableView.contentOffset.y >= (self.tableView.contentSize.height - self.tableView.bounds.size.height)) {
        NSLog(@"bottom!");
        NSLog(@"%@", [self getLastMessageID]);
        [self getMoreStuff:[self getLastMessageID]];
    }

}

This works fine, but the only problem is when the user is pulling the tableview down (like pull to refresh) the code fires. How can I handle this?

like image 278
Sheehan Alam Avatar asked Jul 28 '11 11:07

Sheehan Alam


1 Answers

try this way

    if(self.tableview.contentOffset.y<0){
              //it means table view is pulled down like refresh
              return;
            }
else if(self.tableView.contentOffset.y >= (self.tableView.contentSize.height - self.tableView.bounds.size.height)) {
        NSLog(@"bottom!");
        NSLog(@"%@", [self getLastMessageID]);
        [self getMoreStuff:[self getLastMessageID]];
    }
like image 127
SriPriya Avatar answered Nov 15 '22 20:11

SriPriya