我有一个显示一些内容的 UITableView。当用户向上滚动时,下面的单元格并不总是立即加载。这会在表格底部创建一个空白区域。我想在空白处显示一个微调器,并在内容加载完成后让它消失,但我不确定如何去做。快速实现这样的东西的好方法是什么?
我是编码和 iOS 的新手,如果问题含糊不清或答案显而易见,请原谅我。
示例屏幕截图:
最佳答案
我认为这对你有帮助..
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: .red)
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
应该在数据加载时隐藏。
当上述功能不起作用时,您可以更喜欢这个 link.
关于ios - 当用户滚动但 tableview 单元格加载缓慢时,在 tableview 底部显示微调器的好方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45365139/