ios - 当用户滚动但 tableview 单元格加载缓慢时,在 tableview 底部显示微调器的好方法是什么?

标签 ios swift performance uitableview

我有一个显示一些内容的 UITableView。当用户向上滚动时,下面的单元格并不总是立即加载。这会在表格底部创建一个空白区域。我想在空白处显示一个微调器,并在内容加载完成后让它消失,但我不确定如何去做。快速实现这样的东西的好方法是什么?

我是编码和 iOS 的新手,如果问题含糊不清或答案显而易见,请原谅我。

示例屏幕截图:

sample image for desired behavior

最佳答案

我认为这对你有帮助..

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/

相关文章:

c# - IOS项目如何生成IPA

ios - 我想放置具有不同标签文本颜色的选框标签

ios - 下载 Firebase 存储的 URL 不起作用

c++ - 检查 BOOL 的值是否比更新它更有效?

ios - 如何从 xcode 获取 TestFlight 应用程序的日志

ios - 仅在首次启动时显示 View - Swift 3

JSONDecoder 无法处理空响应

swift - 展开后 TableView 消失

performance - 为什么从多个 SSD 读取的吞吐量比从单个 SSD 读取的吞吐量低

android - Robotium 是否可以可靠地测试 Activity 和 fragment 的启动速度?