15
votes

In a UITableView where the cells contain UITextField objects, does having one of those UITextField objects be the first responder prevent its cell from being re-used?

For example, with a UITableView that has more rows than will fit on the screen, one can tap on a UITextField to bring up the keyboard for the field in that cell. Then scroll the table view to make that cell go off screen. When scrolling back to the cell, I can see calls to -tableView:cellForRowAtIndexPath: for all the cells, except the one that contains the UITextField that currently has first responder status.

This behavior leads me to believe that iOS is aware that my cell contains the first responder and thus chooses not to discard the cell, thus not needing to call the data source to get the cell when it scrolls back into view.

This behavior is desirable, but I am concerned because I have not seen any documentation that indicates that this behavior is guaranteed, and I would hate to rely on it if there are conditions where it isn't true.

Can anyone point me at some documentation about table view cell re-use and first responders that covers this situation?

1
Can you subclass the UITableviewCell and overwrite the method - (void) prepareForReuse {} to see if your cell is coming for reuse.imthi
I'm not sure this is documented, but one thing is sure: you don't have to take it into consideration, since it seems to be automatic.user529758

1 Answers

3
votes

There is no such reference in the official iOS SDK documentation. You are correct to be concerned that this behavior you are observing is not guaranteed and should not be relied upon.