2011-07-25 43 views
1

我在UITableViewCell(CustomCell)中使用NSURLConnection的委託方法。我正在顯示單元格中的下載進度。下載完成後,調用connectionDidFinishLoading。一旦下載完成,我需要刪除顯示下載進度的單元格。它在下圖中解釋。從表中刪除CustomCell

enter image description here

這裏下載在第三單元的文件完成第一,在其他兩個單元的下載量都在進步。一旦下載完成,我需要刪除單元格。在這種情況下,我必須刪除下載完成的第三個單元。
所以,有人幫我刪除connectionDidFinishLoading中的單元格。先謝謝你。

回答

0
while creating cell set the tag 

cell.tag=55; 

in connectdidFinishing u can remove it by 

[[self.view viewWithTag:55] removeFromSuperview]; 
0

當你開始下載和更新自定義單元格以顯示進度,節省indexPath某處您委派

在頭

實施
NSIndexPath *targetCellIP; 
@property (nonatomic, retain)NSIndexPath *targetCellIP; 

@synthesize targetCellIP; 

// Somewhere where you update cell layout to show progress save it's indexPath 
[self setTargetCellIP:....]; 

// After download is completed, remove cell from data model 
[[dataModel objectAtIndex:[targetCellIP section]] 
             removeObjectAtIndex:[targetCellIP row]]; 

// Remove cell from table 
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:targetCellIP] 
       withRowAnimation:UITableViewRowAnimationMiddle]; 

這方法將是好的,只有當你只有一個單元的進度是你想要刪除的時候,其他情況下,您可以將索引存儲在數組中,並在需要時可以使用它們。

+0

或者,你可以將它保存在一個數組中,然後遍歷數組。只用一行甚至更多就完美地工作。 – Simon