gpt4 book ai didi

iphone - “Live”UITableView - 从服务器获取小部分数据

转载 作者:行者123 更新时间:2023-11-29 03:37:52 24 4
gpt4 key购买 nike

如何在 iOS 下创建实时 UITableView?

我的意思是,我想创建连接到用 JAVA 编写的服务器的应用程序。 POST 请求下的服务器返回带有数据的 map 表(JSON 格式)。问题是,数据可能非常大(大约 100000 条记录)。我已经在服务器端实现了部分返回数据(当 POST 具有偏移量和大小参数时,服务器返回从偏移量到(偏移量 + 大小)的数据以及数据总数)。

问题是我不知道如何在 iOS 上实现它。

我知道如何让 UITableView 处理从服务器下载的数据,但我不知道如何让 UITableView 处理部分数据:类似于:在进入查看时,我只下载 100000 行中的 100 行,当用户向下滚动(例如滚动到 80 行)我下载下一部分数据。我的意思是我不想在内存中存储全部 100000 行,而只想在 TableView 中显示 200 行。当用户滚动到表格末尾时,在内存中我应该有从 99800 到 100000 的行

最佳答案

当用户滚动tableview时,我们将检查是否到达最后一个单元格,如果到达最后一个单元格,我们将下载下一个数据集,如下所示:

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

NSInteger sectionsAmount = [tableView numberOfSections];
NSInteger rowsAmount = [tableView numberOfRowsInSection:[indexPath section]];

if ([indexPath section] == sectionsAmount - 1 && [indexPath row] == rowsAmount - 1) {
// This is the last cell in the table
//Here you can download the next part of dataset and reload the tableView.
}
}

希望这对您有所帮助。

关于iphone - “Live”UITableView - 从服务器获取小部分数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18890047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com