How can I determine if the user has scrolled to the last cell/bottom of a UITableView?
Smooth Scrolling:- As a result, it affects the smoother scrolling experience. In UITableVIew, Scrolling will be smooth through cell reuse with the help of prepareForReuse() method.
IndexPath contains information about which row in which section the function is asking about. Base on this numbers you are configuring the cell to display the data for given row.
indexPath(for:)Returns an index path that represents the row and section of a specified table-view cell.
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.frame.size.height)) {
//user has scrolled to the bottom
}
Use NSArray *paths = [tableView indexPathsForVisibleRows];
. Then check if the last object in that array is the indexPath for the final cell.
Source: Another Question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With