UITableView Detecting Last Cell

Ward picture Ward · Jul 13, 2010 · Viewed 32.3k times · Source

How can I detect when a UITableView has been scrolled to the bottom so that the last cell is visible?

Answer

Michael Kessler picture Michael Kessler · Jul 13, 2010

Inside tableView:cellForRowAtIndexPath: or tableView:willDisplayCell:forRowAtIndexPath: like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    ...

    NSInteger sectionsAmount = [tableView numberOfSections];
    NSInteger rowsAmount = [tableView numberOfRowsInSection:[indexPath section]];
    if ([indexPath section] == sectionsAmount - 1 && [indexPath row] == rowsAmount - 1) {
        // This is the last cell in the table
    }

    ...

}