views:

242

answers:

1

Hi,

I have an UITableView with lot of rows. It is like an accordion : http://docs.jquery.com/UI/Accordion Main cells have subcells, subcells have also subcells. So this is a three-levels tableView.

Well, when the user selects a cell, it expands (or collapses) subcells with row animation. But I need to set the new size of the tableView, and the scrollView.

I do all that stuff in this method :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

The problem : When the user tap a cell, then quickly tap a sub one, the second animation isn't done, so subcells of the level 2 aren't shown. But the size has been set (taking in consideration that subcells of level 2 has been shown).

Actually I'm playing with time to handle this... but it really sucks.

Here is a sample of my code :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Checking with times (with 0,5 second interval in order to be sure that the previous animation is finished !)

// Setting tableView & scollView heights

[tableView beginUpdates];
if(position.isExpanded == YES)
    [tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationBottom];
else 
    [tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[tableView endUpdates];
}

So, I would like to catch the end of this animation. Or, playing with a kind of semaphore (but i've only 1 process ...) Any ideas to fix this ?

Please, keep in mind in your replies that I'm really new in iPhone development.

Thanks.

A: 

The animation is controlled by a instance of class CAAnimation. This class supports a method - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag which will be delivered to the delegate of this instance. This information is typically used to get informed on the completion.

In regard to your special request i would have a look at the UIView Class reference. There are several tasks that deal with animations of that view - which is the base class of UITableView. Therefore anything that is valid for UIView should have effect on the table view.

Ralf Edmund