我有个聊天室。我发现当数据太大时,每次我进入聊天室都会延迟3到5秒。
在我的viewWillAppear功能中,我获得了聊天数据和reloadData tableView。
现在我的data.count是49430。
有什么办法可以解决这个问题吗,请帮帮我,谢谢!
发布于 2022-08-08 08:16:42
最好的方法之一是将数据20乘以20 (这里只是一个示例,目的是拆分数据)执行pagination.In命令来执行此操作,后端服务必须可用。
您需要做的是,当用户滚动到willDisplayCell.You中的最后一个单元时,服务将向tableview的willDisplayCell.You发送下20个数据。
示例
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
}
}https://stackoverflow.com/questions/73274450
复制相似问题