2015-12-01 40 views
0

我有一个分组的UITableView,其中我在第二部分中显示了一些汽车数据。我使用SDWebImage从Web服务器加载图像。在其回调中,我调整图片大小并更新图片视图。当更新单元格时,UITableView行分隔符被切断

但是,只要我更新我的图像视图,UITableView分隔符被切断。 为了便于说明我已经给各元素的背景颜色 当图像尚未加载,它看起来像这样:

row separator visible

当图像被更新时,它看起来像这样

enter image description here

请注意,即使没有子视图(UIImageView)将其隐藏,UITableView单元格之间的行分隔符也会以某种方式截断。

根据UITableView部分行高度而变化,所以我已经覆盖了heightForRowAtIndexPath的UITableView委托

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
     if indexPath.section == 0 { 

      return GFFloat(44) 
     } 
     else { 

      return CGFloat(220) 
     } 

    } 

有人能告诉我为什么分隔消失了,我怎么能解决这个问题?当我更新图像时,我已阅读了关于重新下载UITableViewCell的更多信息,但由于我显示了很多汽车,因此当我尝试此操作时,我的应用程序崩溃。

回答

1

只需添加下面的方法它将解决分隔符问题。

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 
     if cell.respondsToSelector("setSeparatorInset:") { 
      cell.separatorInset = UIEdgeInsetsZero 
     } 
     if cell.respondsToSelector("setPreservesSuperviewLayoutMargins:") { 
      cell.preservesSuperviewLayoutMargins = false 
     } 
     if cell.respondsToSelector("setLayoutMargins:") { 
      cell.layoutMargins = UIEdgeInsetsZero 
     } 
    } 
+0

太棒了。你能解释一下为什么会发生切断。我不明白它为什么现在可以工作。 – slashburn

相关问题