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).

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 ["CellDate" sample](http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html) 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 `[self becomeFirstResponder]` on it and when the cell is deselected I call `[self resignFirstResponder]` so it works just fine, but there is some bug.

When I have my custom cell on screen (i.e. not scrolled out off screen) everything is correct, but if I select it

![Selecting custom cell](https://i.stack.imgur.com/GERTQ.png)

scroll tableView down so my cell is no longer on screen

![Scrolled down, custom cells are no longer on screen](https://i.stack.imgur.com/zTSCd.png)

and then select some another cell

![Selecting some other cell while custom cell is no longer on screen](https://i.stack.imgur.com/ZUQDZ.png)

my custom cell won't be deselected

![Unexcpected result](https://i.stack.imgur.com/bbkzb.png).

The only main change in default UITableViewCell's functionality is this:

```
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    if (selected)
    {
        [self becomeFirstResponder];
    }
    else
    {
        [self resignFirstResponder];
    }
}

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

```

using just this method overrides makes this bug to appear: when currently selected custom cell is offscreen it won't deselect for some reason.

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.

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.S. sorry for my bad language, I'm not a native English speaker.

UPDATE:

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.

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.

As for me, that's very strange.