表视图单元格删除动画不起作用

时间:2014-10-14 21:37:57

标签: ios objective-c uitableview animation

-(void)tableView:(UITableView *)tableView 
       commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
       forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.myArray removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                              withRowAnimation:UITableViewRowAnimationFade];
    }
}

将动画类型更改为任何其他选项并没有什么区别,我似乎每次都获得相同的动画。我已经读过这可能是由于iOS 7错误,但我的部署目标是iOS 8。有什么想法吗?

2 个答案:

答案 0 :(得分:0)

if (editingStyle == UITableViewCellEditingStyleDelete)
{
    if ([self.myArray count] >= 1) 
     {
         [self.tableView  beginUpdates];
         [self.tableView  deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
         [self.myArray removeObjectAtIndex:[indexPath row]];
         [self.tableView endUpdates];
      }
} 

试试这个

答案 1 :(得分:0)

你可以这样做,

    NSMutableArray *indexPathsToDelete = [NSMutableArray new];

    for (Object *object in newObjects)
    {
       if (![currentObjects containsObject:object]) {
          int row = [newObjects indexOfObject:object];
          NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
          [indexPathsToDelete addObject:indexPath];
       }
    }

    [tableView beginUpdates];
    [tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
    [tableView endUpdates];