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
2010-07-13 20:52:35
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
2010-07-14 01:41:09
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
2010-07-14 02:29:13
+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
2010-07-13 20:55:54
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
2010-07-13 22:16:01