首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >TableView中的大数据

TableView中的大数据
EN

Stack Overflow用户
提问于 2022-08-08 07:48:22
回答 1查看 62关注 0票数 0

我有个聊天室。我发现当数据太大时,每次我进入聊天室都会延迟3到5秒。

在我的viewWillAppear功能中,我获得了聊天数据和reloadData tableView。

现在我的data.count是49430。

有什么办法可以解决这个问题吗,请帮帮我,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2022-08-08 08:16:42

最好的方法之一是将数据20乘以20 (这里只是一个示例,目的是拆分数据)执行pagination.In命令来执行此操作,后端服务必须可用。

您需要做的是,当用户滚动到willDisplayCell.You中的最后一个单元时,服务将向tableview的willDisplayCell.You发送下20个数据。

示例

代码语言:javascript
运行
复制
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    let lastElement = 20 - 2 // We call it a little before the end so that the user does not notice that the data is coming.

    if indexPath.row == lastElement{
        page = page + 1 // We tell the backend that the page has increased so it will fetch us the next 20 data

        callService() // calling service

    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73274450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档