Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if the user has scrolled to the bottom of the UITableView?

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

like image 947
Sheehan Alam Avatar asked Jul 01 '10 18:07

Sheehan Alam


People also ask

Is UITableView scrollable?

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.

What is IndexPath UITableView?

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.

What is IndexPath in Tableview Swift?

indexPath(for:)Returns an index path that represents the row and section of a specified table-view cell.


2 Answers

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
}
like image 140
Ben Scheirman Avatar answered Oct 07 '22 00:10

Ben Scheirman


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

Source: Another Question

like image 24
jrtc27 Avatar answered Oct 07 '22 01:10

jrtc27