Possible bug in UITableViewCell didTransitionToState:(UITableViewCellStateMask)state

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
 So that I can use an animation block to adjust the opacity of cells that transition to state UITableViewCellStateShowingDeleteConfirmationMask. (I also check for UITableViewCellStateDefaultMask so I can turn them back to normal if the user cancels.) The problem happens thusly:
  1. Swipe cell to delete. The cell fades with the animation block and the delete confirmation button shows up as we would expect. GOOD!
  2. (If we tap away to cancel, the cell returns to normal.) GOOD!
  3. 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.
  4. The cell directly after the deleted one moves up into the proper place BUT THEN DIMS ACCORDING TO the logic in the

    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:


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 I added:
tableView.editing = NO;
 right before removing the data source and deleting the rows. Apparently the “swipe to delete” automatically puts the tableView into edit mode and doesn’t bother to get it out of edit mode automatically. It feels like what was going on was that the UITableView cell directly after the deleted one was inheriting the deleted one’s UITableViewCellStateMask and since it was in edit mode, the willTransitionToState got called automatically. Setting the editing property of the tableView before deleting seems to reset the state mask.

Here’s a picture and also a tiny preview of what I’m working on!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: