views:

273

answers:

2

I have added custom animation to UITableViewCells. Each cell has its own animation. When I pop the view, the animations continue and I get a bad exec error because the animation is trying to access the deallocated cells.

How do I stop the animations before the view is deallocated?

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {  
    self.Currentcell = [tableView cellForRowAtIndexPath:indexPath];
    [UIView beginAnimations:@"fade" context:nil];
    [UIView setAnimationDuration:0.4];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [self.Currentcell.accessoryView viewWithTag:1].alpha = 0;
    [self.Currentcell.accessoryView viewWithTag:2].alpha = 1;
    [UIView setAnimationDidStopSelector:@selector(animationEnded:finished:context:)];
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];
}

- (void)animationEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {  
    [UIView beginAnimations:animationID context:context];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [cell.accessoryView viewWithTag:1].alpha = 1;
    [cell.accessoryView viewWithTag:2].alpha = 0;
    [UIView commitAnimations];
}
A: 

I don't know how your animation code looks like (maybe you could post some?), so I can just guess. Basically, you probably need to implement -viewWillDisappear: method in your view controller and stop any running animations there.

Matthes
can you show me some example how to stop animate?
RAGOpoR
Actually I cannot because you didn't post any code, so I've got no idea how you create and handle your animations. Post your code so we can see what's going on and try to figure out the solution.
Matthes
update it! thanks for you advise
RAGOpoR
A: 

This thread says that commitAnimations should retain your view, so it should not be deallocated when it's still animating. Maybe you're over-releasing the view somewhere? Build and Analyze (available in Xcode 3.2+ afaik) might help to spot that.

Nick
thanks for your suggestion Nick
RAGOpoR