【问题标题】:Remove CustomCell from table从表中删除 CustomCell
【发布时间】:2011-07-25 09:59:30
【问题描述】:

我在 UITableViewCell(CustomCell) 中使用 NSURLConnection 的委托方法。我在单元格中显示下载进度。下载完成后,将调用 connectionDidFinishLoading。下载完成后,我需要删除显示下载进度的单元格。如下图所示。

这里首先完成了第三个单元格中文件的下载,其他两个单元格中的下载正在进行中。下载完成后,我需要删除单元格。在这种情况下,我必须删除下载完成的第三个单元格。
所以,有人帮我删除 connectionDidFinishLoading 中的单元格。提前谢谢你。

【问题讨论】:

    标签: iphone ios4 uitableview nsurlconnection


    【解决方案1】:
    while creating cell set the tag 
    
    cell.tag=55;
    
    in connectdidFinishing u can remove it by
    
    [[self.view viewWithTag:55] removeFromSuperview];
    

    【讨论】:

      【解决方案2】:

      当您开始下载并更新自定义单元格以显示进度时,将 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];
      

      仅当您只有一个要删除的进度单元格时,此方法才会很好,在其他情况下,您可以将索引存储在数组中并在需要时使用它们。

      【讨论】:

      • 或者,您可以将其保存在一个数组中,然后循环遍历该数组。只需一行或更多行即可完美运行。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多