2015-12-01 41 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

相關問題