Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - deleting row from UITableView doesn't animate

I have a very frustrating issue. I have an app with a UITableView. When I am removing a cell from the table view, it is removed from the data model and then I call the following:

-(void)removeItem:(NSIndexPath *)indexPath {
    [self.tableView beginUpdates];

    [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                      withRowAnimation:UITableViewRowAnimationRight];
    [self.tableView endUpdates];
}

My problem is, I've tried it like I do above, and I've tried without using animateWithDuration. I've even tried with a CATransaction, but however I do it, the animation doesn't happen.

I've got slow animations on in my Simulator and when I remove an item from the list, it removes correctly, but without animation. It just disappears and leaves a blank space for a moment before the table view data is reloaded.

I've search all over SO and Google and I can't seem to find an answer. Any ideas?

Does it perhaps have to do with the fact that I'm removing the object from the data model before calling the function above?

Edit: Removed the Animation Block as it is incorrect

like image 991
Daniel Retief Fourie Avatar asked Dec 06 '25 03:12

Daniel Retief Fourie


1 Answers

According to THIS you don't need to use the animateWithDuration:animations: at all.

Just try it like this

-(void)removeItem:(NSIndexPath *)indexPath {
    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                  withRowAnimation:UITableViewRowAnimationRight];
    [self.tableView endUpdates];
}
like image 153
IluTov Avatar answered Dec 08 '25 17:12

IluTov