Is the following post still the accepted way of detecting when an instance of UITableView has scrolled to the bottom [in Swift], or has it been altered (as in: improved) since?
Problem detecting if UITableView has scrolled to the bottom
Thank you.
willDisplayCell: used here for smoother UI (single cell usually displays fast after willDisplay: call). You could also try it with tableView:didEndDisplayingCell: . Much better for knowing when all the cells load that are visible. However this will be called whenever the user scrolls to view more cells.
Since a scrollView has a panGesture we can check the velocity of that gesture. If the tableView was programmatically scrolled the velocity in both x and y directions is 0.0. By checking this velocity we can determine if the user scrolled the tableView because the panGesture has a velocity.
UITableView scrolls back because it's content size is equal to it's frame (or near to it). If you want to scroll it without returning you need add more cells: table view content size will be large then it's frame.
try this
func scrollViewDidScroll(_ scrollView: UIScrollView) { let height = scrollView.frame.size.height let contentYoffset = scrollView.contentOffset.y let distanceFromBottom = scrollView.contentSize.height - contentYoffset if distanceFromBottom < height { print(" you reached end of the table") } }
or you can find in this way
if tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height) { //you reached end of the table }
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