iphone - UITableView 懒加载单元格数据

标签 iphone objective-c uitableview

我需要在我的 UITableView 中实现某种延迟加载。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //... some initializations here

    //this is a function that pulls my cell data using helper class
    NSData *cellData=[MyDataClass dataForCellAtIndexPath:indexpath.row];

    //... here I populate pulled data to cell

    return cell;
}

一切正常,但是表格 View 滚动不流畅,因为dataForCellAtIndexPath 方法很慢。所以我需要通过调用这个方法来实现将数据延迟填充到单元格中。我期望的结果是表格 View 将平滑滚动,但单元格的内容将在绘制单元格后稍微填充。请帮帮我,怎么办?

最佳答案

是的,您可以考虑将数据收集推送到后台线程。首先要尝试的是最简单的选项,看看它是否有任何改进:

[MyDataClass performSelectorInBackground:@selector(dataForCellAtIndexPath:) withObject:indexpath.row];

post提到了其他一些更复杂的可自定义选项,例如 Grand Central DispatchNSThread .

关于iphone - UITableView 懒加载单元格数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10092293/

相关文章:

iphone - 'a' 链接不适用于 iPhone Safari 中的 html5 视频标签

objective-c - Objective-C 中的结构继承?

ios - Objective-C 单元附件 View

ios - 是否可以合并 UITableView 中的单元格,以便我可以在右侧添加一些图像?

iphone - 显示 UITableView 溢出?

ios - 当单元格的元素的框架改变时更新 tableView

iphone - 在以下情况下保存应用程序状态数据的最佳方法是什么?

iphone - 如何计算图表上某人体重的 y 像素? (数学+编程题)

ios - 根据给定位置显示谷歌导航

iphone - 检查当前时间是否在时间 A 和 B 之间