Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch an animation end in deleteRowsAtIndexPaths

I was wondering if there is any possibility to catch if animation fired during deleteRowsAtIndexPaths did end? What I am trying to do is removing some all rows from UITableView except one that i tapped. Next I want to insert few rows into the same UITableView. Both operations are performed in separates beginUpadate/endUpdate blocks. The problem is that before deleting animation ends, the inserting animation starts and I want it be fired one after another because inserted rows are coming from external webservice.

I was thinking about wrapping inserting and deleting methods (in UITableView subclass) in methods where I could replace standard animation with custom ones and use objective-c blocks to fire one after another when the first ends but it appears to be imposible or I just can't do it.

Thanks in advance for your help!

like image 793
pawel.kalisz Avatar asked Aug 09 '12 08:08

pawel.kalisz


1 Answers

I believe that wrapping your table update in animateWithDuration would work:

[UIView animateWithDuration:0.0 animations:^{
    [coursesTable beginUpdates];
    …
    [coursesTable endUpdates];
} completion:^(BOOL finished) {
    // Code to run when table updates are complete.
}];

Other methods that I found suggested here on Stack Overflow did not work for me.

I used this technique at one time and tested it enough to verify that the completion block was called after I called the table's endUpdates method and the time that it was called seemed reasonable, but I rewrote my code so I didn't need it any more before I had completely verified that the animation was actually finished.

like image 50
David Hull Avatar answered Dec 28 '22 14:12

David Hull