title: UITableViewCell selector setSelected:animated: gets called many times?
body: <p>I've discovered a strange behavior with <strong>setSelected:animated:</strong> in my custom UITableViewCell class. I discovered that this function gets called multiple times if I click on a cell in my table. I am wondering if this is normal behavior or a bug in my code.</p>
  
  <p>To help with debugging, I've modified the <strong>setSelected:animated:</strong> function in my custom UITableViewCell class implementation as such:</p>
  
  <pre><code>- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  
  [super setSelected:selected animated:animated];
  
  // Configure the view for the selected state.
  if (selected)
      NSLog(@"Yes %X", &amp;self);
  else
      NSLog(@"No %X", &amp;self);
  
  }
  </code></pre>
  
  <p>If I click on a cell in the simulator, here is what I get in the console:</p>
  
  <pre><code>2011-03-22 22:05:26.963 marketPulse[3294:207] Yes BFFFDDD0
  2011-03-22 22:05:26.964 marketPulse[3294:207] Yes BFFFDE30
  </code></pre>
  
  <p>You would think that I would get only 1 entry, since I only clicked on 1 cell.</p>
  
  <p>And if I click on a different cell after that:</p>
  
  <pre><code>2011-03-22 22:07:11.014 marketPulse[3294:207] No BFFFD890
  2011-03-22 22:07:11.016 marketPulse[3294:207] No BFFFDD00
  2011-03-22 22:07:11.017 marketPulse[3294:207] Yes BFFFDDD0
  2011-03-22 22:07:11.017 marketPulse[3294:207] Yes BFFFDE30
  </code></pre>
  
  <p>If I click on the same cell 2 times in a row, I get more than 2 <strong>Yes</strong>:</p>
  
  <pre><code>2011-03-22 22:08:41.067 marketPulse[3294:207] Yes BFFFDDD0
  2011-03-22 22:08:41.068 marketPulse[3294:207] Yes BFFFDE30
  2011-03-22 22:08:41.069 marketPulse[3294:207] Yes BFFFDE30
  </code></pre>
  
  <p>The more times I click the same cell, the more <strong>Yes</strong> I will get, and if I click on a different cell after that, I'll get a lot of <strong>No</strong></p>
  
  <p>I put a breakpoint  before the NSLog, and looking at the debugger, it seems that all the repeated calls are coming from the same object.</p>
  
  <p>Here is a part of my <strong>tableView:cellForRowAtIndexPath:</strong> function so you can see how my cells are being treated:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
  
  static NSString *ContentCellIdentifier = @"newsTableCellContent";
  
  UITableViewCell *cell;
  
  
  //index of cell data in tableData
  NSUInteger index = indexPath.row / 2;
  
  ...
  
  //content of story
  else if( [indexPath row] % 2 == 1 ) {
  
      cell = [tableView dequeueReusableCellWithIdentifier:ContentCellIdentifier];
  
      if (cell == nil) {
          NSArray *topLevelObjects = [[NSBundle mainBundle]
                                      loadNibNamed:@"newsTableCells"
                                      owner:nil options:nil];
  
          for (id currentObject in topLevelObjects) {
              if ( [currentObject isKindOfClass:[newsTableCellContent class]] ) {
                  cell = currentObject;
                  break;
              }
          }
      }
  
      ((newsTableCellContent *)cell).content.text = [[tableData objectAtIndex:index] description];
  
  }   
  
  return cell;
  }
  </code></pre>
  
  <p>Everything works fine so its hard to tell if the repeat calls to <strong>setSelected:animated:</strong> are intentional or not. If this is normal operation, I can make do with another method, but I would just like to know if this is suppose to happen or not.</p>
  
  <p>Thanks</p>