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
2010-07-01 18:44:39
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
2010-07-01 18:46:07
what is the math?
Sheehan Alam
2010-07-06 05:02:30
added a formula you can use...
Ben Scheirman
2010-07-06 22:58:23
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
2010-07-10 17:56:19
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
2010-07-11 16:09:42