Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell subview disappears when cell is selected
    primarykey
    data
    text
    <p>I'm implementing a color-chooser table view where the user can select amongst, say, 10 colors (depends on the product). The user can also select other options (like hard drive capacity, ...).</p> <p>All color options are inside their own tableview section.</p> <p>I want to display a little square on the left of the textLabel showing the actual color.</p> <p>Right now I'm adding a simple square UIView, give it the correct background color, like this :</p> <pre><code>- (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; } </code></pre> <p>This displays fine without problems.</p> <p>My only problem is that when I select a "color" row, during the fade-to-blue selection animation, my custom UIView (colorThumb) is hidden. It gets visible again just after the selection/deselection animation ended, but this produces an ugly artifact.</p> <p>What should I do to correct this? Don't I insert the subview at the right place?</p> <p>(There's nothing special in the didSelectRowAtIndexPath, I just change the cell's accessory to a checkbox or nothing, and deselect the current indexPath).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload