简体   繁体   中英

UITableView doesn't animate deletion if multiple cells

I have my UITableView (swipe) deletion method set up in the standard fashion.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {

        [self.tableView beginUpdates];

        /*
        code…
        */

        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView endUpdates];
        }   
}

The UITableViewRowAnimationFade animation works perfectly if there is only one cell in the table view or if I am deleting the last cell, but if I try to delete a row above the last one, it will no longer use the animation when I hit delete. How can I fix this?

Also, I am using a custom cell (just a label and an image view) if it makes any difference.

This is a bit late, but for anyone having this issue, I have created a test project that replicates the required functionality, with animation working perfectly for all cells.

It's available here: https://github.com/sdods3782/TVTTableViewTest

However, I was unable to recreate the issue. I don't know what was causing the problem for the original poster, but using TVTTableViewTest as an example, it should hopefully prevent other people from having the same problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM