I got an iOS app with table view. When i select rows several times, information in selected one duplicate.
You can see it on a picture:

I add cell’s in this way:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
UILabel *label = [[UILabel alloc] init];
Place *item = [source objectAtIndex:indexPath.row];
[label setFont:[UIFont fontWithName:@"PermianSansTypeface" size:15.0]];
label.text =item.name;
label.frame = CGRectMake(5, 5, 310, 35);
[cell addSubview:label];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
OnePlaceViewController *placeView = [[OnePlaceViewController alloc] initWithNibName:@"OnePlaceViewController" bundle:nil];
placeView.nom = indexPath.row;
placeView.source = source;
placeView.route = route;
placeView.titleView = titleView;
/*
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selected = NO;
*/
[self.navigationController pushViewController:placeView animated:YES];
}
Why do information duplicate? Thnx.
I think the problem is that you’re adding
UILabelas subView everytime. Since cells are reused, everytime the table reloads, multipleUILabels are added. So, my suggestion would be to go through all the subviews of the cell and remove them before adding new label.