Search code examples
objective-cuitableviewcore-animation

2 Questions about customizing a UITableView


I have 2 questions that I am having trouble answering.

I have a UITableView and when you touch a cell, it changes its height and inserts a sub view with some detail.

The problem is that when I select another cell, there is no obvious way to collapse the other cell. What I did as a temporary fix is run a loop whenever you select a cell, and on each cell, if its not the one you selected, it collapses it. This does not seem efficient, does anyone have an idea?

Second question is, whenever I collapse a cell, it animates. but it removes the detail subview kind of jarringly, is there a way to wait till the cell is done animating to remove it? I cannot find an appropriate delegate method.

Thanks in advance.


Solution

  • Perhaps the best way would be to have a variable that stores the index path (row) of the previously touched cell. Then, test to see if the current cell's index is not equal to the previous, collapse the previous cell and open the new one.

    For your second issue, can you not animate the collapse before you remove the subview? I assume you're using [UIView beginAnimations] (or something similar). Set the duration of the animation [UIView setAnimationDuration:1.0], and then after you commit the animations, do [self performSelector:@selector(collapseCell) withObject:nil afterDelay:1.0].

    I've not tested this, and I'm going off of memory, so sorry if it doesn't work as you'd hoped, but perhaps it can get you going in the right direction.

    Edit: Apologies, I didn't see your "Core Animation" tag. The second solution may not be right for you.