0

我已将自定义动画添加到 UITableViewCells。每个单元格都有自己的动画。当我弹出视图时,动画继续,我得到一个糟糕的 exec 错误,因为动画正试图访问已释放的单元格。

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

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

2 回答 2

1

这个线程说 commitAnimations 应该保留你的视图,所以当它还在动画时不应该被释放。也许您在某处过度释放视图?构建和分析(在 Xcode 3.2+ afaik 中可用)可能有助于发现这一点。

于 2010-03-28T11:02:17.020 回答
0

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

于 2010-03-23T13:58:42.127 回答