一次将所有日期从 firebase 加载到 tableview,但我想一次加载 10 个项目,当我再次滚动到底部时,10 个项目应该加载到 tableview,下面是我的代码
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = items[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "inciCell") as!
IncidentCell
cell.delegate = self
cell.setupCell(with: item, indexPath)
return cell
}
}
最佳答案
在委托(delegate)方法
cellForRowAtIndexPath
中,您可以检查类似indexPath.row == items.count - 1
的内容。如果为真,那么您将从您的数据库中获取 10 个项目并将其
附加
到您的`items。然后执行
tableView.reloadData()
以使用 10 个新项目更新 TableView 。
您还可以在表格 View 的底部 (tableFooterView
) 制作一些不错的微调器。但这可能是下一步。
希望对您有所帮助。
关于ios - 滚动到底部时一次加载 10 个项目在 tableview ios、swift、Firebase 上加载更多项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47497127/