I am using the standard table view datasource protocol to delete table cells:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle == UITableViewCellEditingStyleDelete)
{
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
I would like to run some other code once the animation is completed but the deleteRowsAtIndexPaths:withRowAnimation method does not have a completion block. How else would I run some code after this method completes?
For iOS 6 Apple added - tableView:didEndDisplayingCell:forRowAtIndexPath:
to UITableViewDelegate
. You should be able to use it to get a callback immediately when each UITableViewCell
has been removed from the display, so if you know you've started a deletion animation on a particular index path then you can use it as a usually reliable means of knowing that the animation has ended.
(aside: I guess if the user scrolled the cell off screen during its animation then you could get a false positive, but such things are going to be so unlikely that I'd be likely to add a basic guard against persistent negative consequences and not worry about the ephemeral ones, such as if I end up showing an empty cell when the mid-deletion object is scrolled back onto screen because I already removed it from my store)
I believe one way to do this is to implement UITableViewDataSource
's method tableView:commitEditingStyle:forRowAtIndexPath:
and execute a delayed performance method there inside.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (UITableViewCellEditingStyleDelete == editingStyle) {
[self performSelector:@selector(delayedMethod) withObject:nil afterDelay:0.1];
}
}
-(void)delayedMehtod {
// Your code here...
}
It may not be as pretty as a "completion" block but I'm sure it would do the trick.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With