I’m putting this out here on the internets because I was pulling my hair out about this problem I had. Let me see if I can explain the problem and how I ended up solving it without turning this into a super long story.
I’m working on a new app that is basically a brewer’s countdown timer. I have a UITableViewController with a UITableView that has some custom UITableViewCells created via subclassing.
In the UITableViewCell subclass I implement:
- (void)didTransitionToState:(UITableViewCellStateMask)state
- Swipe cell to delete. The cell fades with the animation block and the delete confirmation button shows up as we would expect. GOOD!
- (If we tap away to cancel, the cell returns to normal.) GOOD!
- If instead, of tapping away, we tap “delete”, the
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
gets called and we delete the cell from the table and the data source programmatically. It flies away. SO FAR SO GOOD. - The cell directly after the deleted one moves up into the proper place BUT THEN DIMS ACCORDING TO the logic in the
didTransitionToState:(UITableViewCellStateMask)state
method. BAD!
The cell directly afterwards should not be getting the didTransitionToState method called on it. This problem persisted if I was using reusable cells or not. Here’s how I solved it:
In
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
tableView.editing = NO;
Here’s a picture and also a tiny preview of what I’m working on!