2010-03-23 57 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