swift - 使用自定义部分和单元格 Swift 滚动到底部 TableView
问题描述
我tableview
有自定义sections
和cells
. 每次用户滚动到底部时,它都会调用服务器并加载额外的数据。我的问题是如何检测最后一个section
以便加载更多数据?每个section
包含 1 到 3 rows
。我willDisplay
的工作不正常,refreshControl.beginRefreshing()
指标也没有显示。谢谢!
let refreshControl = UIRefreshControl()
//MARK - Header Sections
func numberOfSections(in tableView: UITableView) -> Int {
return tableData[segmentedControlIndex].count
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell") as! HomeSectionTableViewCell
let model = events[segmentedControlIndex][section]
cell.setup(model: model)
.
.
.
return cell.contentView
}
//MARK - Cells
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData[segmentedControlIndex][section].rows.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "detailCell") as! HomeTableViewDetailCell
.
.
.
cell.detailTitleLabel?.text = tableData[segmentedControlIndex][indexPath.section].rows[indexPath.row].detailTitleLabelString
cell.detailSubtitleLabel?.text = tableData[segmentedControlIndex][indexPath.section].rows[indexPath.row].detailSubtitleLabelString
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.000001
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell: HomeTableViewDetailCell = tableView.cellForRow(at: indexPath) as? HomeTableViewDetailCell {
cell.detailTitleLabel?.numberOfLines = cell.detailTitleLabel?.numberOfLines == 0 ? 1 : 0
tableView.reloadData()
}
}
//MARK - TableView add more data
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.section == tableView.numberOfSections - 1 {
self.refreshControl.beginRefreshing()
self.page = self.page + 1
self.getMoreData() { result in
self.refreshControl.endRefreshing()
print("Load More Bets Data reload: \(result == true ? "Success":"Failure")")
}
}
}
解决方案
推荐阅读
- python - Pandas:在 CSV 中查找每下 10 个数据点的平均值
- flutter - Flutter 包 widgets.dart、material.dart 和 cupertino.dart 有什么区别,使用哪一个?
- javascript - 等待设备并响应网页
- java - 如何将条目添加到 CalendarFX MonthPage?
- javascript - 更新 mobx 存储时重新渲染组件
- python - 将 Rawsql 查询数组转换为格式化的 html 表
- javascript - 练习反应式编程
- php - 从正则表达式中得到错误“在偏移量 1 处没有重复的内容”
- ios - 异常没有被捕获
- batch-file - 在 echo 命令的末尾批量附加一些东西