Irregular animations from UITableView's deleteRowsAtIndexPaths:withRowAnimation:

廉价感情. 提交于 2019-12-20 19:13:27

问题


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.

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.


回答1:


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




回答2:


Try adding [tableView beginUpdates]; and [tableView endUpdates];




回答3:


Maybe setting the alpha on the cell works as suggested here. Not sure though. problems with animation when deleting the last row of a TableView in ios7



来源:https://stackoverflow.com/questions/19474665/irregular-animations-from-uitableviews-deleterowsatindexpathswithrowanimation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!