views:

56

answers:

2

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

+2  A: 

Implement the tableView:willDisplayCell:forRowAtIndexPath: method in your UITableViewDelegate and check to see if it's the last row.

Art Gillespie
thanks for the tip. I'm actually using this method to trigger an event and it looks like because it's "Will" display, it happens before it actually displays the cell. Is there a method that fires after the cell is displayed?
Ward
Alas, no. You could fudge a little by using `performSelector:withObject:afterDelay` with a very short delay to call a method that does what you need.
Art Gillespie
+1  A: 

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
    }

    ...

}
Michael Kessler
you might as well have said I'm a dummy. thanks for the help sometimes I think these things are harder than they are.
Ward