kris
kris

Reputation: 2526

IOS UITableview how to take action after table animations complete

How can I cause action to be taken upon completion of a UITableview's animation?

I'm attempting to shrink a UITableview cell and remove a subview of the cell that's not visible after the shrinkage. To shrink the cell, I'm calling [tableview beginUpdates] and [tableview endUpdates], and changing the height of the cell as returned by theheightForRowAtIndexPath datasource method of the UITableview.

The challenge is, i need the tableview to complete shrinking so the subview is out of sight before I can remove the subview. if I put the code to remove the subview from the cell right after (or before or between) the to call [tableview endUpdates] then the subview is removed too soon (it doesn't wait for the animation) and it looks funny.

My thought is i'd like to be able to setup a callback that runs upon completion of the animation, and remove the subView in the callback

Upvotes: 8

Views: 2381

Answers (2)

Rudolf Adamkovič
Rudolf Adamkovič

Reputation: 31486

What about this?

[CATransaction begin];

[CATransaction setCompletionBlock:^{
    // animation has finished
}];

[tableView beginUpdates];
// shrink the cells
[tableView endUpdates];

[CATransaction commit];

Upvotes: 19

SeriousSam
SeriousSam

Reputation: 229

Try Using NSNotifications class. Post Notifications when something is about to happen, and later after something has happened. You can use a bool in the same notification method to toggle between 'about to happen' and 'has happened'.

Upvotes: -4

Related Questions