当滚动到底部加载更多项目iOS,Swift,Firebase上的更多项目时,加载10个项目



一次加载所有日期从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
    }
}
  1. 在委托方法中cellForRowAtIndexPath您可以检查诸如indexPath.row == items.count - 1

  2. 之类的东西
  3. 如果是真的,那么您从DB中获得10个项目,并将其 append获得到您的项目。

  4. 然后做tableView.reloadData()以使用10个新项目更新表视图。

您还可以在表视图的底部(tableFooterView)中制作一些不错的旋转器。但这可能是下一步。

希望它有帮助。

最新更新