TableView显示一些索引后重复的数据

我使用自定义表格视图单元格和我的表格视图显示索引5后重复的数据我不知道为什么它完成当在iPad中它显示索引8重复数据后它可能是索引问题,但找不到它下面是代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString * CellIdentifier = @“item”;

ItemCell *cell = (ItemCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[ItemCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSLog(@"indexpath.row is %d",indexPath.row);

NSString *stre = [grouporphoto objectAtIndex:indexPath.row];
if([stre isEqualToString:@"Group"]){
    folderimage = YES;
    NSLog(@"here is folder");

    cell.item = [items objectAtIndex:indexPath.row];


}
else if([stre isEqualToString:@"Photo"]){
    folderimage = NO;
    NSLog(@"here is Photo");

    cell.item = [items objectAtIndex:indexPath.row];


}




return cell;
}

请帮助提前致谢


您应该重置所有变量在另一个else语句中,以便当您的单元格被重用时,它们中的变量不会被重用。

else
{
    cell.item = nil;
}

这应该为你解决它。


这是因为iOS处理TableViews的方式。 只要一个新的单元格进入视图(从视图之外,即在屏幕底部以下),它会要求一个新的单元格,在这种情况下,它会尝试重用已移出视图的单元格。

由于重用,并非所有实例变量都在单元上重置。 你需要明确地改变你想改变的一切 。 换句话说,所有图片,文字,标签等等,你希望每个单元格可能不同,每次都明确地设置它们。

链接地址: http://www.djcxy.com/p/60495.html

上一篇: TableView showing repeated data after some index

下一篇: How can I remove table cell values in objective c?