title: UITableView per-cell selection mode while editing
body: <p>In my <code>UITableView</code>, when it enters editing mode, I'd like only a select few cells to be selectable. I know the <code>UITableView</code> class has the property <code>allowsSelectionDuringEditing</code>, but this applies to the whole <code>UITableView</code>. I don't see any relevant delegate methods to set this on a per-cell basis.</p>
  
  <p>The best solution I can come up with is to set <code>allowsSelectionDuringEditing</code> to <code>YES</code>. Then, in <code>didSelectRowAtIndexPath</code>, filter out any unwanted selections if the table view is editing. Also, in <code>cellForRowAtIndexPath</code>, change those cells <code>selectionStyle</code> to None.</p>
  
  <p>The problem with this is that going into editing mode does not reload the <code>UITableViewCells</code>, so their <code>selectionStyle</code> doesn't change until they scroll offscreen. So, in setEditing, I also have to iterate over the visible cells and set their <code>selectionStyle</code>.</p>
  
  <p>This works, but I just wonder if there is a better/more elegant solution to this problem. The basic outline of my code is attached. Any suggestions greatly appreciated! Thank you.</p>
  
  <pre><code>- (void) tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
  
      if (self.editing &amp;&amp; ![self _isUtilityRow:indexPath]) return;
      // Otherwise, do the normal thing...
  }
  
  - (UITableViewCell*) tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
  
      // UITableViewCell* cell = ...
  
      if (self.editing &amp;&amp; ![self _isUtilityRow:indexPath])
      {
          cell.selectionStyle = UITableViewCellSelectionStyleNone;
      }
      else
      {
          cell.selectionStyle = UITableViewCellSelectionStyleBlue;
      }
  
      return cell;
  }
  
  - (void) setEditing:(BOOL)editing animated:(BOOL)animated {
  
      [super setEditing:editing animated:animated];
  
      if (editing)
      {
          for (UITableViewCell* cell in [self.tableView visibleCells])
          {
              if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
              {
                  cell.selectionStyle = UITableViewCellSelectionStyleNone;
              }
          }
      }
      else
      {
          for (UITableViewCell* cell in [self.tableView visibleCells])
          {
              if (![self _isUtilityRow:[self.tableView indexPathForCell:cell]])
              {
                  cell.selectionStyle = UITableViewCellSelectionStyleBlue;
              }
          }
      }
  }
  </code></pre>