下面的帖子是否仍然是检测UITableView实例在Swift中滚动到底部时被接受的方法,还是从那以后是否对其进行了更改(如:改进)?
Problem detecting if UITableView has scrolled to the bottom
谢谢。
发布于 2017-05-31 17:22:39
Swift 3
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row + 1 == yourArray.count {
print("do something")
}
}
发布于 2016-08-18 02:02:37
试试这个:
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")
}
}
或者你可以试试这个方法:
if tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height) {
/// you reached the end of the table
}
发布于 2018-10-07 23:38:27
我们可以避免使用scrollViewDidScroll
和tableView:willDisplayCell
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.section == tableView.numberOfSections - 1 &&
indexPath.row == tableView.numberOfRows(inSection: indexPath.section) - 1 {
// Notify interested parties that end has been reached
}
}
这应该适用于(任意数量的节)。
https://stackoverflow.com/questions/39015228
复制相似问题