我要在显示最后一个单元格时在UITableView的底部添加一个ActivityIndicator,同时获取更多数据,然后在获取数据时将其隐藏。
所以我滚动到底部->显示的最后一行->获取数据时微调器开始旋转->获取数据,隐藏微调器->添加到tableview的新数据。
关于如何实现此目标的任何提示?
谢谢 ;)
最佳答案
添加此功能
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let lastSectionIndex = tableView.numberOfSections - 1
let lastRowIndex = tableView.numberOfRows(inSection: lastSectionIndex) - 1
if indexPath.section == lastSectionIndex && indexPath.row == lastRowIndex {
// print("this is the last cell")
let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.startAnimating()
spinner.frame = CGRect(x: CGFloat(0), y: CGFloat(0), width: tableView.bounds.width, height: CGFloat(44))
self.tableview.tableFooterView = spinner
self.tableview.tableFooterView?.isHidden = false
}
}
和tableFooterView应该在数据加载时隐藏。
关于ios - 加载时将ActivityIndicator添加到UITableView的底部,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42457343/