有时,当我在 UITableView 中选择 1 行时,另一行也会变成选中状态。错误可能在哪里?
在didSelectRowAtIndexPath:
cartCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
cell.crossImage.hidden = NO;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
cell.crossImage.hidden = YES;
}
在我的cellForRowAtIndexPath
static NSString *CellIdentifier = @"cellCart";
cartCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[cartCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Join *join = [_fetchByRecipe objectAtIndexPath:indexPath];
cell.ingredientName.text = join.ingredient.name;
cell.ingredientCount.text = [NSString stringWithFormat:@"%@", join.count];
cell.ingredientUnit.text = join.ingredient.units;
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.crossImage.hidden = YES;
}
else {
cell.crossImage.hidden = NO;
}
return cell;