swift - 如何知道该行何时位于视图顶部以在 UITableView Swift 中获取更多数据?
问题描述
我有一个用 Swift 编写的具有 UITableView 的 IOS 消息传递应用程序。消息按日期时间从最旧的顶部和最近的底部显示。
当行索引为 0 时,我正在加载更多数据,但我无法弄清楚它是如何工作的。
当用户第一次加载 messageViewController 时,它会下载该对话的消息,如下所示:
internal func messagesDownloaded(page: MessagePage) {
//append page.content to messages (content) array
for index in 0..<page.content.count {
self.content.insert(page.content[index], at: index)
}
self.progressBar.isHidden = true
self.LOG.info("reload table")
self.tableView.reloadData()
scrollToBottom()
}
然后,如果 ui 位于顶部或 row 为 0(零),则使用以下函数 fetchMore() 数据:
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if (tableView.numberOfRows(inSection: 0) - 1) == indexPath.row {
LOG.info("the top has reached: row: \(indexPath.row)")
downloadCheck(indexPath.row)
}
}
但是,当第一行可见时,if 子句永远不会进入,所以我知道何时获取更多数据。什么是最好的方法?
解决方案
推荐阅读
- scala - 从 scala 中的 BsonArray 获取值
- python - 如何使用 pyautogui 等待特定图像出现在屏幕上?
- android - Android toast show() 方法不再显示相同的 toast
- salesforce - #kentico cms 到 salesforce 社区登录 SSO
- javascript - 将数组作为属性附加到模块数组中的模块?
- python - 字典结构(dict -> dict)与列表比较
- symfony - 用于加载夹具数据的自己的命令
- keras - 如果steps_per_epoch 不适合样本数量怎么办?
- javascript - Jest - 测试 try/catch
- android - 应用程序终止时推送通知不调用 OnMessageReceive