首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >检测UITableView何时滚动到底部

检测UITableView何时滚动到底部
EN

Stack Overflow用户
提问于 2016-08-18 01:59:00
回答 4查看 54.3K关注 0票数 52

下面的帖子是否仍然是检测UITableView实例在Swift中滚动到底部时被接受的方法,还是从那以后是否对其进行了更改(如:改进)?

Problem detecting if UITableView has scrolled to the bottom

谢谢。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2017-05-31 17:22:39

Swift 3

代码语言:javascript
运行
AI代码解释
复制
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if indexPath.row + 1 == yourArray.count {
        print("do something")
    }
}
票数 60
EN

Stack Overflow用户

发布于 2016-08-18 02:02:37

试试这个:

代码语言:javascript
运行
AI代码解释
复制
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")
    }
}

或者你可以试试这个方法:

代码语言:javascript
运行
AI代码解释
复制
if tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height) {    
    /// you reached the end of the table
}
票数 107
EN

Stack Overflow用户

发布于 2018-10-07 23:38:27

我们可以避免使用scrollViewDidScrolltableView:willDisplayCell

代码语言:javascript
运行
AI代码解释
复制
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
    }
}

这应该适用于(任意数量的节)。

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39015228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档