UITableView cell insertion animation synchronization and view resizing

I am implementing a custom view that has a UITableView as a subitem. This custom view is also a delegate of the specified UITableView. My intention is to have two levels of cells. Higher levels can be clicked so that they collapse and show lower levels.

uncollapsed

By clicking on a cell named "category B", this should happen:

collapsed

As you can see in the pictures, when the first-level cell is clicked (and -tableView:didSelectRowAtIndexPath: ), the table expands (I use -insertRowsAtIndexPaths:withRowAnimation: to insert the "B1 subcategory" into the table).

I want this custom view to be exactly the same size as the visible contents of the table inside. Right now, after inserting a new cell, I'm telling the user view to reset its frame with the new height of the contents of the UITableView.

The problem is with the animation: I cannot synchronize the UITableView insertion animation and the custom view frame by changing its height. I can make the view expanded and then animate the insert or animate the insert first, and then change the frame of the custom view.

Is there a way to synchronize these actions so that they are performed in one animation?

+4
source share

All Articles