title: How to do (custom) selection with custom UITableViewCell subclass
body: <p>I have a <code>UITableView</code> with a custom <code>UITableCellView</code> subclass. I want to show one of the rows as active or selected. The controls in my cell have their own gestures, but I have area on the right where I can do the selection. I had (naively) thought I could just indicate I wanted a checkmark style accessory but Apple's docs say</p>
  
  <blockquote>
    <p>This control does not track touches. The delegate of the table view
    can manage check marks in a section of rows (possibly limiting the
    check mark to one row of the section) in its
    tableView:didSelectRowAtIndexPath: method.</p>
  </blockquote>
  
  <p>I'm not sure how to interpret that, but I put the <code>tableView:didSelectRowAtIndexPath:</code> method in my delegate, and it never fires. Regardless of where I touch my cell (on the part where there are touchable controls or not). So I'm curious why that doesn't work? I also noticed that regardless of how I set the <code>selected</code> property on the cells, the checkmark always shows on, so I don't think it's really meant to be used a selection indicator.</p>
  
  <p>But I'm actually kind of OK with that. I don't really want a checkmark, I'd rather do something like mail does when it does multi select on the left side, the radio-button-esque style circles. Which then leads me to a quandary about how to proceed. Should I just add a button control to the right side, manipulate the images appropriately in my custom cell subclass? Do I mess with the background image of the button in that case? Or just the image? And since selecting one needs to deselect the others, what's the best way to connect this to the table view delegate, rather than the subclass? Or should I make a custom NSView subclass?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I removed the accessory. I added an UIImageView to show selection state. Because the sub control in my cell uses a hold gesture, the selection tap makes it through just about everywhere for the cell. I synchronize the visual selection state using the following method:</p>
  
  <pre><code>- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
      [super setSelected:selected animated:animated];
      self.selectionView.image = self.selected ? [UIImage imageNamed: @"selected"] : [UIImage imageNamed: @"not_selected"];
  }
  </code></pre>
  
  <p>To my custom controller, I added the following method:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      [Site setCurrent: self.allSites[indexPath.row]];
      [[Site current] pullValves];
  }
  </code></pre>
  
  <p>It finally donned on me that that the first method was for updating the visual state, but not for responding to the users intent, that belongs in the second method. The first fires at various times, but the second applies when the user actually does the tap.</p>
  
  <p>Finally, I had to programmatically set</p>
  
  <pre><code>self.clearsSelectionOnViewWillAppear= NO;
  </code></pre>
  
  <p>Not matter what I set in the storyboard, that value was <code>YES</code>, so returning to the list was clearing my selection.</p>