Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Irregular animations from UITableView's deleteRowsAtIndexPaths:withRowAnimation:

Summary: In editing mode, I'm deleting rows in a table view using a custom editing control, rather than the default red minus sign and delete confirmation button. Tick a row or multiple rows, then tap the Delete button in the tool bar. It's similar to the behavior seen in the Mail app. See the screenshot below.

enter image description here

Problem: The animations produced by calls to deleteRowsAtIndexPaths:withRowAnimation: are irregular. For example, here's what happens when I use the Bottom row animation (i.e., UITableViewRowAnimationBottom) to delete the ticked row (Subject #7) in the screenshot:

  1. Subject #8 slides underneath and behind Subject #7
  2. Subject #8 is briefly hidden behind Subject #7
  3. Subject #8 replaces Subject #7 jarringly

This is occurring on both the simulator and on a device. The Automatic animation type (i.e., UITableViewRowAnimationAutomatic) produces the same irregular behavior when deleting Subject #7 above.

The Top animation type works as expected in the simulator but produces inconsistent, jarring animations on a device.

The Fade type animation is the only animation that works as expected in both the simulator and on a device.

Details:

I'm targeting iOS 7, and using storyboard, pure auto layout, and Core Data.

Here's the action method where I delete the rows:

- (void)deleteButtonTapped:(UIBarButton *)sender
{
    // update table view's data
    [self.listOfItems removeObjectsAtIndexes:self.indexSetOfTickedRows];

    // create index paths for ticked rows
    NSMutableArray *indexPaths = [[NSMutableArray alloc] init];

    [self.indexSetOfTickedRows enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
        [indexPaths addObject:[NSIndexPath indexPathForRow:idx inSection:0]];
    }];

    [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationBottom];

    // update Core Data and UI...
}

What I have tried:

The table cell subclass overrides layoutSubviews. However, the irregular animations persist even when I comment out layoutSubviews.

I also removed the custom tickable editing control from the table cells, then hard-coded the deletion of a specific row in the action method. The irregular animations persisted.

As suggested by others, I've tried calling deleteRowsAtIndexPaths:withRowAnimation: between calls to beginUpdates and endUpdates. This does not resolve the issue.

Any suggestions on what to do next, or best guesses as to why I am seeing these irregular animations?

Update (iOS 7.1):

Issue remains after targeting iOS 7.1. Will continue to rely on fade animation.

like image 985
bilobatum Avatar asked Oct 20 '13 06:10

bilobatum


1 Answers

Try calling [self.listOfItems removeObjectsAtIndexes:self.indexSetOfTickedRows]; at the end of the function instead of at the beginning.

like image 141
Sumeet Avatar answered Nov 16 '22 01:11

Sumeet