Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView-cellForRowAtIndexPath需要半秒钟以上的时间_Ios_Performance_Uitableview_Lag - Fatal编程技术网

Ios UITableView-cellForRowAtIndexPath需要半秒钟以上的时间

Ios UITableView-cellForRowAtIndexPath需要半秒钟以上的时间,ios,performance,uitableview,lag,Ios,Performance,Uitableview,Lag,我用可重用的单元格构建了一个UITableView。在我的代码中的某个时刻,我需要在某个特定的索引XPath上访问一个单元格,所以我调用 MyCell *cell = (MyCell *) [tableView cellForRowAtIndexPath:indexPath]; 有时(通常是第一次)调用此函数,可能需要0.5到1秒的时间 什么会导致这种情况?我如何预防这种情况 我查了一下 (UITableViewCell *)tableView:(UITableView *)tableView

我用可重用的单元格构建了一个UITableView。在我的代码中的某个时刻,我需要在某个特定的索引XPath上访问一个单元格,所以我调用

MyCell *cell = (MyCell *) [tableView cellForRowAtIndexPath:indexPath];
有时(通常是第一次)调用此函数,可能需要0.5到1秒的时间

什么会导致这种情况?我如何预防这种情况

我查了一下

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
作为对cellForRowAtIndexpath的反应被调用:但事实并非如此

编辑:

我刚刚做了另一个测试,如果我打电话也需要很长时间

  [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];

无论首先调用什么,都会有半秒的延迟,这可能会迫使tableView加载其数据。但是,如果一个单元格在屏幕上不可见,它可能不会被加载到内存中。

最好看看bodycellForRowAtIndexPath创建单元格的方法,如果它不存在的话,包括各种各样的UI手臂摆动。如果您只需要当前未显示的单元格中的数据,那么直接访问数据源的效率要高得多。我知道,但我不需要单元格的数据,我想根据数据设置单元格的样式。例如,我必须更改标签的文本,并且不希望仅为此而导致完全重新加载数据。如果要“设置”单元格的样式,则应仅对现有单元格或系统要求的单元格执行此操作。“设置”当前未显示的单元格的样式是无用的(而且是一种严重的时间浪费)。你是对的,尽管我认为已经调用了重新加载数据。细胞是在我没想到的时候创建的。