3

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.

William Remacle
  • 1,480
  • 2
  • 16
  • 24
  • Duplicate of: http://stackoverflow.com/questions/7198633/how-can-i-tell-when-a-uitableview-animation-has-finished. Well, maybe that one is a duplicate of this one, but it has the benefit of having a working answer. – fishinear Jul 29 '13 at 16:28
  • Duplicate and the answer is really bad. anyone reach this question shoudl have a look at [Callback for UITableView animations](http://stackoverflow.com/questions/2802146/callback-for-uitableview-animations) and [UITableView row animation duration and completion callback](http://stackoverflow.com/questions/3832474/uitableview-row-animation-duration-and-completion-callback) – River2202 Oct 25 '15 at 13:42

2 Answers2

0

In addition:

You can get the animation by checking NSArray *animationKeys = [cell.layer animationKeys]; and calling CAAnimation *animation = [cell.layer animationForKey:_a_key_];. Afterwards you can set the delegate and catch the completion as described above.

GiloTM
  • 1
  • 1
0

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
  • 1,015
  • 7
  • 10