views:

57

answers:

2

How can I determine if the user has scrolled to the last cell/bottom of a UITableView?

A: 

Use NSArray *paths = [tableView indexPathsForVisibleRows];. Then check if the last object in that array is the indexPath for the final cell.

Source: Another Question

jrtc27
A: 

UITableView inherits from UIScrollView, and scroll view exposes a contentOffset property (documentation here).

Use this with a bit of math to determine if the contentOffset is within frame.size.height of the bottom.

Update: here's a stab at a formula that will give you what you want:

if(tableView.contentOffset.y >= (tableView.contentSize.height - tableView.size.height)) {
  //user has scrolled to the bottom
}
Ben Scheirman
what is the math?
Sheehan Alam
added a formula you can use...
Ben Scheirman
Code is almost there! I can detect the bottom, but when I get to the bottom the code in the if block gets called many times if the user holds the scroll position. How can I resolve?
Sheehan Alam
Maybe you could add a timer when scrolling, invalidate any current timer, and once the timer fires (say after 250ms) then you could execute your code.Without more details it's very hard to suggest the right thing though.
Ben Scheirman