title: Custom UITableViewCell with canBecomeFirstResponder YES won't deselect when offscreen
body: <p>I recently happend to find some interesting bug in UITableView regarding selection and deselection functionality. (m.b. it's not a bug per se, but I find this situation very abnormous).</p>
  
  <p>Prehistory: I was trying to create some custom TableViewCell class that will be able to use UIDatePicker to pick some date and place it in cell's label. The <a href="http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html" rel="nofollow noreferrer">"CellDate" sample</a> is not very good for me. So I was trying to set some custom inputView to cell and make it first responder. After some time of researches I found the way to override readonly inputView property of my custom UITableViewCell subclass, and now it works perfectly: when the cell is selected I call <code>[self becomeFirstResponder]</code> on it and when the cell is deselected I call <code>[self resignFirstResponder]</code> so it works just fine, but there is some bug.</p>
  
  <p>When I have my custom cell on screen (i.e. not scrolled out off screen) everything is correct, but if I select it</p>
  
  <p><img src="https://i.stack.imgur.com/GERTQ.png" alt="Selecting custom cell"></p>
  
  <p>scroll tableView down so my cell is no longer on screen</p>
  
  <p><img src="https://i.stack.imgur.com/zTSCd.png" alt="Scrolled down, custom cells are no longer on screen"></p>
  
  <p>and then select some another cell</p>
  
  <p><img src="https://i.stack.imgur.com/ZUQDZ.png" alt="Selecting some other cell while custom cell is no longer on screen"></p>
  
  <p>my custom cell won't be deselected</p>
  
  <p><img src="https://i.stack.imgur.com/bbkzb.png" alt="Unexcpected result">.</p>
  
  <p>The only main change in default UITableViewCell's functionality is this:</p>
  
  <pre><code>- (void)setSelected:(BOOL)selected animated:(BOOL)animated
  {
      [super setSelected:selected animated:animated];
  
      if (selected)
      {
          [self becomeFirstResponder];
      }
      else
      {
          [self resignFirstResponder];
      }
  }
  
  - (BOOL)canBecomeFirstResponder
  {
      return YES;
  }
  </code></pre>
  
  <p>using just this method overrides makes this bug to appear: when currently selected custom cell is offscreen it won't deselect for some reason.</p>
  
  <p>My question is: did anyone experience something like this and is there anything I can do? Because apart from this I have a perfect solution for my problem of date cell.</p>
  
  <p>Is that not a correct way to work with UITableViewCells? Am I doing something completely wrong? I'm just starting to learn iOS, so I'm maybe not very familiar with some of it's aspects.</p>
  
  <p>P.S. sorry for my bad language, I'm not a native English speaker.</p>
  
  <p>UPDATE:</p>
  
  <p>I've found out some more details. After some research I figured out, that when you scroll your tableView and hide some tableViewCell offscreen it's (cell) is being destroyed. And when you scroll back it is being created again via call to tableView's delegate's tableView:cellForRowAtIndexPath:
  Apart from this if you will try to call [tableView cellForRowAtIndexPath:indexPath] for indexPath of row, that is being offscreen, tableView will return you a nil.</p>
  
  <p>But the strange thing is: when your custom cell is being firstResponder, apparently, it won't be recreated via tableView's delegate's tableView:cellForRowAtIndexPath: and it won't be accessible via [tableView cellForRowAtIndexPath:indexPath] neither.</p>
  
  <p>As for me, that's very strange.</p>