Synchronize animations of UITableView cell insertion and the resizing of a view
===

I'm implementing a custom view that has a UITableView as a subview. This custom view is also the delegate of said UITableView. My intention is to have two levels of cells. The higher level ones can be clicked so that they collapse and show the lower level ones.

![uncollapsed][1]

By pressing the cell named "category B" this should happen:

![collapsed][2]

As you can see in the pictures, when a first level cell is clicked (and `-tableView:didSelectRowAtIndexPath:` is called) the table expands (I'm using `-insertRowsAtIndexPaths:withRowAnimation:` to insert "sub-category B1" into the table).

I want this custom view to be the exact same size of the visible content of the table inside. Right now, after the insertion of the new cell, I'm telling the custom view to reset it's frame with the new UITableView content height.

The problem comes with the animation: I can't synchronize the UITableView insertion animation and the custom view's frame changing it's height. I can make the view expand and then animate the insertion, or animate the insertion first and then change the frame of the custom view.

**Is there a way to synchronize this actions so that they are performed into a single animation?**


  [1]: http://i.stack.imgur.com/hTxRY.png
  [2]: http://i.stack.imgur.com/wFyuI.png