As soon as the cell is no longer visible on the screen I need to be notified.
UITableView already has a delegate method called tableView:didEndDisplayingCell:forRowAtIndexPath: but this delegate method never gets called. And yes I do have the delegate for my UITableView set.
Any other ways to detect a cell being removed? I need to be able to save the content (inputs) of this cell before it’s being reused by another item.
EDIT:
According to the documentation tableView:didEndDisplayingCell:forRowAtIndexPath: is iOS 6 and higher API. Is there a way to achieve this on iOS 5?
On versions of iOS older than 6.0, the table view doesn’t send the
tableView:didEndDisplayingCell:forRowAtIndexPath:message.If you are using a subclass of
UITableViewCell, you can get the same effect on older versions of iOS by overridingdidMoveToWindow:You may need to give your cell a (weak or unsafe_unretained) reference back to your table view delegate so you can send the delegate a message.
However, you can’t rely only on
didMoveToWindowfor all versions of iOS. Before iOS 6, a table view always removed a table view cell as a subview before reusing it, so the cell would always receivedidMoveToWindowbefore being reused. However, starting in iOS 6, a table view can reuse a cell without removing it as a subview. The table view will simply change the cell’s frame to move it to its new location. This means that starting in iOS 6, a cell does not always receivedidMoveToWindowbefore being reused.So you should implement both
didMoveToWindowin your cell subclass, andtableView:didEndDisplayingCell:forRowAtIndexPath:in your delegate, and make sure it works if both are called, or if just one is called.