Reputation: 3
I've searched around, it seems that most recommendations are to simply [tableView reloadData].
However, I am after animation on deletion of the cell. If you can imagine a checklist, I add items to the checklist and once the item/task on the checklist (EG: "Get milk from milk bar") is completed I remove the item/task by tapping on it. At which point I want the cell to disappear with animation.
As mentioned above, most people just recommend a route which would involve me removing the item from the array it is held in and simply reloading the tableview, but that's completely void of animation.
Below is what I've tried as an alternative with little success.
[tableView beginUpdates]
[tableView deleteRowsAtIndexPaths:[self.taskArray objectAtIndex:indexPath.row] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates]
Note: The taskArray is populated with task's I enter. Additionally, the above code resides within the "didSelectRowAtIndexPath" method. Any tips as to what im doing wrong or what I could do instead?
TLDR; I want to remove a cell with animation from the tableView simply by tapping on it.
Upvotes: 0
Views: 599
Reputation: 877
In your didSelectRowAtIndexPath
// Delete from the taskArray
[self.taskArray removeObjectAtIndex:indexPath.row];
// Remove row from the tableview
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
Upvotes: 0
Reputation: 1232
Just a quick observation, the API is requesting that you provide an array of index paths and you only pass the actual item you're wanting for deletion.
What happens if you try:
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
Upvotes: 1