I am getting duplicates in UITableView, cellForRowAtIndexPath
Posted
by
Martol1ni
on Stack Overflow
See other posts from Stack Overflow
or by Martol1ni
Published on 2012-10-22T21:42:41Z
Indexed on
2012/10/22
23:00 UTC
Read the original article
Hit count: 128
I am getting duplicates of my array, and wrongly displayed cells in this method:
Here I am initializing the array, and adding it to the 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];
For some weird reason there are always the 4th object that is messed up, and is either duplicated, or do not have the views from IB. Here is the cellForRowAtIndexPath: method:
- (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;
}
I have logged the string [[_tableArray objectAtIndex:2] objectAtIndex:indexPath.row]
, and it logs the right string.
© Stack Overflow or respective owner