Я реализую табличное представление выбора цвета, в котором пользователь может выбирать, скажем, 10 цветов (в зависимости от продукта). Пользователь также может выбрать другие параметры (например, емкость жесткого диска и т. Д.).
Все параметры цвета находятся в их собственном разделе tableview.
Я хочу отобразить маленький квадрат слева от textLabel, показывающий фактическое цвет.
Прямо сейчас я добавляю простой квадрат UIView, задаю ему правильный цвет фона, например:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:RMProductAttributesCellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:RMProductAttributesCellID] autorelease];
cell.indentationWidth = 44 - 8;
UIView *colorThumb = [[[UIView alloc] initWithFrame:CGRectMake(8, 8, 28, 28)] autorelease];
colorThumb.tag = RMProductAttributesCellColorThumbTag;
colorThumb.hidden = YES;
[cell.contentView addSubview:colorThumb];
}
RMProductAttribute *attr = (RMProductAttribute *)[_product.attributes objectAtIndex:indexPath.section];
RMProductAttributeValue *value = (RMProductAttributeValue *)[attr.values objectAtIndex:indexPath.row];
cell.textLabel.text = value.name;
cell.textLabel.backgroundColor = [UIColor clearColor];
UIView *colorThumb = [cell viewWithTag:RMProductAttributesCellColorThumbTag];
colorThumb.hidden = !attr.isColor;
cell.indentationLevel = (attr.isColor ? 1 : 0);
if (attr.isColor) {
colorThumb.layer.cornerRadius = 6.0;
colorThumb.backgroundColor = value.color;
}
[self updateCell:cell atIndexPath:indexPath];
return cell;
}
Это отображается нормально без проблем.
Моя единственная проблема в том, что когда я выбираю "цвет" row, во время анимации выделения с переходом в синий цвет мой пользовательский UIView (colorThumb) скрыт. Он снова становится видимым сразу после завершения анимации выделения / отмены выделения, но при этом возникает уродливый артефакт.
Что мне делать, чтобы исправить это? Разве я не вставляю подвид в нужное место?
(В didSelectRowAtIndexPath нет ничего особенного, я просто меняю аксессуар ячейки на флажок или ничего и отменяю выбор текущего indexPath).