uitableview 的预加载单元格 [英] Preload cells of uitableview

查看:107
本文介绍了uitableview 的预加载单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我承认 UITableview 在用户滚动时动态加载一个单元格.我想知道是否有一种方法可以预加载所有单元格,以便在滚动时不加载每个单元格.我需要预加载 10 个单元格.这可能吗?

I acknowledge that UITableview load dynamically a cell when user scrolls. I wonder if there is a way to preload all cells in order not to load each one while scrolling. I need to preload 10 cells. Is this possible?

推荐答案

可以初始化表格视图单元格,将它们放入数组 precomputedCells 和数据源委托方法 tableView:cellForRowAtIndexPath: 从数组中返回预先计算的单元格,而不是调用 dequeueReusableCellWithIdentifier:.(类似于您在静态表视图中所做的操作.)

You can initialize table view cells, put them into an array precomputedCells and in the data source delegate method tableView:cellForRowAtIndexPath: return the precomputed cells from the array instead of calling dequeueReusableCellWithIdentifier:. (Similar to what you would do in a static table view.)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    return [self.precomputedCells objectAtIndex:indexPath.row];
}

看一看可能也有用WWDC 2012 Session 211在 iOS 上构建并发用户界面"其中展示了如何在后台线程中填充表格视图单元格的内容,同时保持用户界面响应.

It might also be useful to have a look at the WWDC 2012 Session 211 "Building Concurrent User Interfaces on iOS" where it is shown how to fill the contents of table view cells in background threads while keeping the user interface responsive.

这篇关于uitableview 的预加载单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆