Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation complete notification after UITableView is manually reordered

UITableView has that built-in animation in which after a cell is reordered, it lays gently into the vacant space. Is there a where to tap into some sort of notification after that animation ends? I would like to call a method upon completion. At the moment I'm using performSelector:withObject:afterDelay: which works fine at the moment, but I would like to know if it's possible to tap into animation complete.
To reiterate, I'm not talking about custom animation, only the animation built into UITableView.

I've been searching around and can't seem to gather an answer.

like image 578
Gobot Avatar asked Mar 16 '12 03:03

Gobot


1 Answers

I realize that this question is ancient, but I still stumbled across it when I was trying to find an answer to the same problem that @Gobot was having. Well, turns out that there is a SIMPLE solution. Like what @Mitchell Vanderhoeff stated, you need to insert the method

- (void)tableView:(UITableView *)tableView
        moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
        toIndexPath:(NSIndexPath *)toIndexPath {
        [CATransaction setCompletionBlock:^{
            // Completion code here
        }];
}

in your tableview delegate to get notice from the tableview that it's about to move a row. The key though is the CATransaction setCompletionBlock. This will let you set a completion block on the implicit animation transaction which the tableview is doing for the row movement. Just like the name implies, whatever you put in that block will be executed after the animation has completed.

You will need to include the QuartzCore framework if it's not already part of your project.

like image 62
Will Moore Avatar answered Nov 19 '22 10:11

Will Moore