I'm wondering if I've somehow stumbled upon a bug where swipe to delete UITableViewCells
don't ever deallocate when their UITableViewController
does.
I've added a -dealloc method into my custom table cell, which logs out a message. When I press back on the navigation controller, all 6 messages are logged out.
If I swipe to delete one (or more), and press back, only 5 are logged. So I log out the pointer address of the cell that has been deleted, for future reference. Now when I go back and pause the execution at any point, I can enter into the lldb prompt:
po 140382950334240
<TableLeakCell: 0x7fe67852a490; baseClass = UITableViewCell; frame = (-375 176; 375 44); text = 'Chris'; hidden = YES; autoresize = W; gestureRecognizers = <NSArray: 0x7fe678530d70>; layer = <CALayer: 0x7fe67852a860>>
This should have been deallocated! The x.position
of the cell is exactly -(tableView.width)
, and hidden=YES
. As in the cell is still in the position after the animation has finished. Or perhaps it's being queued for reuse? Either way, it's there forever, and there's nothing in Apple's documentation about having to manually destroy a cell after calling deleteRowsAtIndexPaths.
Quick proof of concept project here: https://github.com/iOSDigital/UITableViewLeak