title: iOS UITableViewCell setSelected:animated: always has animated = NO
body: <p>I'm trying to make my own selection animation. I've created a subclass of UITableViewCell. I do my selection animation in <code>-setSelected:animated:</code> method. It works as intended when you select or deselect cells by tapping them. Problem is that animation is also seen during scrolling, since <code>-setSelected:animated:</code> is called on each cell before it appears. This is how reusing cells mechanism works, I get it. What I don't get is that it always calls this method with animated = NO either on tap or on scroll. This seems like a logic mistake to me. I presumed it was supposed to select cells with animation when you tap them and without animation when reused cell appears. Is <code>animated</code> parameter even ever used anywhere except manual calls? Here's my code:</p>
  
  <pre><code>- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  
      BOOL alreadySelected = (self.isSelected) &amp;&amp; (selected);
      BOOL alreadyDeselected = (!self.isSelected) &amp;&amp; (!selected);
  
      [super setSelected:selected animated:animated];
  
      if ((alreadySelected) || (alreadyDeselected)) return;
  
      NSLog(@"Animated selection: %@", animated ? @"YES" : @"NO");
  
      NSTimeInterval duration;
  
      if (animated) {
  
          duration = 0.25;
  
      } else {
  
          duration = 0.0;
  
      }
  
      [CATransaction begin];
      [CATransaction setAnimationDuration:duration];
  
      if (selected) {
  
          //layer properties are changed here...
  
  
      } else {
  
          //layer properties are changed here... 
  
      }
  
  
      [CATransaction commit];
  
  
  }
  </code></pre>
  
  <p>This always goes without the animation.
  I can't think of any other such an easy way to handle custom selection. Implementing <code>-didSelectRow</code> methods in controller seems so much worse and it's not called during scrolling, so reused cells will appear in a wrong state. Any idea how to fix this?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've found a temporary solution:</p>
  
  <pre><code>#pragma mark - Table View Delegate 
  
  - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
      [cell setSelected:YES animated:YES];   
      return indexPath; 
  }
  
  
  - (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
  
      UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
      [cell setSelected:NO animated:YES];
  
      return indexPath;      
  }
  </code></pre>
  
  <p>It does work, but I don't like it. The fact that TableView's delegate has to know something about selection and it's not all contained in one place bugs me a lot. And <code>-setSelected</code> is called twice when taping a row - with and without animation.</p>