繁体   English   中英

当我滚动UITableView时,数据管理不当

[英]Data is mismanaged when I scroll the UITableView

我在cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中使用以下代码

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(currentRow >=[finalArray count]) return cell;
// Configure the cell.


for(int ii=0;ii<[keys count];ii++){
NSString *no22=[dict objectForKey:[keys objectAtIndex:ii]];
no=[NSString stringWithFormat:@"%@ %"[keys objectAtIndex:ii],]  
}// end of the for loop


if(searching) 
    cell.text = [copyListOfItems objectAtIndex:indexPath.row];
else {
cell.text=[finalArray objectAtIndex:currentRow];

    currentRow=currentRow+1;
}
    return cell;

}

当我滚动表数据时,我得到的奇怪行为是完全错误管理的,请提出任何建议。

是因为您正在重用单元格。 您可以重用更多类型的单元格。

以及为什么要执行if(currentRow >=[finalArray count]) return cell; 这个?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM