2010-03-23 171 views
0

我已将自定义动画添加到UITableViewCells。每个单元格都有自己的动画。当我弹出视图时,动画继续,并且由于动画试图访问释放的单元格,导致执行错误。iPhone:如何停止视图中的动画视图释放前

如何在释放视图之前停止动画?

- (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]; 
} 

回答

0

我不知道你的动画代码是怎么样的(也许你可以发布一些?),所以我可以猜测。基本上,您可能需要在您的视图控制器中实现-viewWillDisappear:方法,并停止所有正在运行的动画。

+0

你能告诉我一些例子如何停止动画? – RAGOpoR 2010-03-23 14:37:45

+1

其实我不能,因为你没有发布任何代码,所以我不知道你如何创建和处理你的动画。发布您的代码,以便我们可以看到发生了什么,并尝试找出解决方案。 – Matthes 2010-03-23 14:55:03

+1

更新它!感谢您的建议 – RAGOpoR 2010-03-23 15:29:05

1

This thread表示commitAnimation应该保留您的视图,所以在它仍然是动画时不应该释放它。也许你在某处过度释放视图?构建和分析(可用于Xcode 3.2 + afaik)可能有助于发现这一点。

+0

感谢您的建议尼克 – RAGOpoR 2010-03-28 16:15:43