Running another code after viewing the table

I use the standard datasource table data protocol to remove table cells:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if(editingStyle == UITableViewCellEditingStyleDelete) { [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } 

I want to run another code after the animation is complete, but the deleteRowsAtIndexPaths: withRowAnimation method does not have a completion block. How else can I run some code after completing this method?

+4
source share
2 answers

For iOS 6, Apple added - tableView:didEndDisplayingCell:forRowAtIndexPath: to UITableViewDelegate . You should be able to use it for an immediate call when every UITableViewCell been removed from the screen, so if you know that you started the delete animation at a specific pointer path, you can use it as a reliable means of knowing that the animation has ended.

(aside: I think if the user scrolls the cell off the screen during its animation, then you could get a false positive, but such things will be so unlikely that I will probably add basic protection against constant negative consequences and not worry about ephemeral, for example, if in the end I show an empty cell when an object with the middle of deletion scrolls back to the screen, because I already deleted it from my store)

+7
source

I believe that one way to do this is to implement the UITableViewDataSource tableView:commitEditingStyle:forRowAtIndexPath: method and execute the delayed performance method 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 the "completion" block, but I'm sure it will be a trick.

Hope this helps!

+2
source

Source: https://habr.com/ru/post/1499244/


All Articles