Iphone 我在UITableView、cellForRowAtIndexPath中获得了重复项

Iphone 我在UITableView、cellForRowAtIndexPath中获得了重复项,iphone,ios,uitableview,Iphone,Ios,Uitableview,我获得了数组的副本,并且在此方法中错误显示了单元格: 在这里,我正在初始化数组,并将其添加到tableView: NSArray *sectionsArray = [NSArray arrayWithObjects: @"Location", @"Front Post", @"Front Fixing", @"Front Footplate", @"Rear Post", @"Read Fixing", @"Rear Footplate", @"Horizontal Bracing", @"Di

我获得了数组的副本,并且在此方法中错误显示了单元格:

在这里,我正在初始化数组,并将其添加到tableView:

NSArray *sectionsArray = [NSArray arrayWithObjects: @"Location", @"Front Post", @"Front Fixing", @"Front Footplate", @"Rear Post", @"Read Fixing", @"Rear Footplate", @"Horizontal Bracing", @"Diagonal Bracing", @"Front Beam", @"Front Lock", @"Rear Beam", @"Rear Lock", @"Guard", @"Accessories", @"Comments", @"Off load ref", @"Loc Empty", @"Loc Affected", nil];
[_tableArray setObject:sectionsArray atIndexedSubscript:2];
[_tableView reloadData];
出于某种奇怪的原因,总是有第四个对象出错,或者重复,或者没有IB的视图。下面是CellForRowatineXpath:方法:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell;
    if (indexPath.section == 2) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"EntryCell"];
        cell.tag = indexPath.row;
        UILabel *label = (UILabel *)[cell viewWithTag:3];
        [label setText:[[_tableArray objectAtIndex:2] objectAtIndex:indexPath.row]];
    }
return cell;
}

我已经记录了字符串
[[u tableray objectAtIndex:2]objectAtIndex:indexath.row]
,它记录了正确的字符串。

删除
cell.tag=indexath.row

因为您正在重用单元格并分配
标记将使其混淆。例如,对于第二行,指定tag=2,然后向下滚动时,将tag=6指定给同一行。

添加以下行:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}
else
{

 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

尝试删除
cell.tag=indexPath.row