title: Custom UITableViewCell and animation on setSelected:animated:
body: <p>I have a <code>UITableViewCell</code> subclass that does its drawing in a drawRect: method. The whole rectangle is custom drawn, including the background.
  I was able to get very complex cells while keeping the scrolling very smooth.</p>
  
  <p>My problem: I call <code>[table deselectRowAtIndexPath:path animated:YES];</code> whenever the view appears, in order to comply with Apple's HIG. However, no animation occurs. It worked when I had a custom view (created with subviews) that was transparent (so Apple's background would appear below), of course. Now it doesn't.</p>
  
  <p>My drawRect: is called once during the "animation time", about halfway through. I think this happens because it's animating the highlighted property of the cell from 1 to 0 and it snaps to 0 when it drops below 0.5.</p>
  
  <p>How can I animate this transition? My guess would be to use the usual beginAnimations: etc. and animate a custom floating point field in my cell object from 1 to 0. Will this call <code>drawRect:</code> repeatedly to animate?</p>
  
  <p><strong>Update</strong>
  I managed to get this almost working. I've overridden setSelected:animated: like so:</p>
  
  <pre><code>- (void) setSelected:(BOOL)selected animated:(BOOL)animated {
      [super setSelected:selected animated:NO];
  
      if (animated) {
          [CATransaction begin];
          CATransition* animation = [CATransition animation];
          animation.type = kCATransitionFade;
          animation.duration = 0.6;
          [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
          [view.layer addAnimation:animation forKey:@"deselectRow"];
          [CATransaction commit];
      }
  }
  </code></pre>
  
  <p>This works perfectly if the table view is on-screen. But if I'm returning to the table view from navigation (back), instead of fading from selected to not selected, it fades from invisible to not selected. What can cause this?</p>