swift3 - 滚动到底部作为分页时从 API 加载更多数据的最佳方法
问题描述
我想在 UITableView 中滚动到底部时根据页码从 API 中获取更多日期
是否使用此方法
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (((scrollView.contentOffset.y + scrollView.frame.size.height) > scrollView.contentSize.height ) && ! isLoadingList){
self. isLoadingList = true
self. loadMoreItemsForList()
}
}
或使用此方法
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
// fetch new data if user scroll to the last cell
guard isLoadingIndexPath(indexPath) else { return }
if self.totalItems > orders.count {
fetchNextPage()
}
}
解决方案
滚动到底部时使用func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
方法获取更多数据。
推荐阅读
- javascript - 未捕获的类型错误:$(...).find(...).not(...).size 不是函数
- macos - 用于从登录窗口切换用户的 Apple 脚本
- r - 在 geom_text 中指定标签的位置
- authentication - Strapi / Nuxt - 找不到自定义路线
- bash - 我对 bash (macOS) 中的“sed”语句有疑问
- java - 可滚动微调器不显示来自 json API 的项目
- gradle - 升级 Gradle 后“无法解析所有配置文件”
- sql - 根据日期名称获取整月日期
- javascript - VueJS 和 Firebase 存储:如何等到图像上传完成后再将 URI 提交到数据库?
- r - 将 for 循环转换为 foreach 循环