Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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滚动条上的单元格无重新查询/重画_Ios_Uitableview - Fatal编程技术网

Ios UITableView滚动条上的单元格无重新查询/重画

Ios UITableView滚动条上的单元格无重新查询/重画,ios,uitableview,Ios,Uitableview,我注意到,当滚动到视图外时,这些单元格会从内存中取出,然后在滚动到视图中时又被添加回内存 我知道这是出于性能原因,但是由于我的表只有几个单元格无法查看,有没有办法关闭此缓存功能?您可以尝试为每个索引路径使用不同的单元格标识符 这样,UITableView将无法找到要退出队列的单元格,并将提供一个新的单元格 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)ind

我注意到,当滚动到视图外时,这些单元格会从内存中取出,然后在滚动到视图中时又被添加回内存


我知道这是出于性能原因,但是由于我的表只有几个单元格无法查看,有没有办法关闭此缓存功能?

您可以尝试为每个索引路径使用不同的单元格标识符

这样,
UITableView
将无法找到要退出队列的单元格,并将提供一个新的单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString * CellIdentifier = [NSString stringWithFormat:@"%d - %d", indexPath.row, indexPath.section];
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    return cell;
}
您也可以完全跳过排队/取消排队,自己保留对它们的引用,然后只需在
单元格中返回它们,以获得rowatinexpath

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

其中
myCells
是一个数组,其中包含您的
UITableViewCell
s.

为什么要将其关闭?我正处于一个十字路口,一个涉及更多代码,但没有什么好处,而另一个涉及更少代码,具有相同好处。第二种方法是我的问题:)我经常在不滚动的表上使用第二种方法。这是一个好办法。