2015-09-29 50 views
0

我使用動態單元格的UITableView。每個單元格都有一些按鈕,一個圖像和一個標籤。圖像的寬度等於tableview寬度,高度是可變的。UITableView是laggy和滾動時跳轉

我正在用函數更新cellForRowAtIndexPath中圖像的高度以尊重寬高比。標籤可以有一個或多個行。

我正在使用heightForRowAtIndexPath來設置單元格的高度。我正在計算它並返回值。

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 

    let queficient = CGFloat(dataController.Data[indexPath.row].width)/self.view.frame.size.width 

    let imgHeight = CGFloat(dataController.Data[indexPath.row].height)/queficient 

    return 134 + imgHeight + heightForView(dataController.Data[indexPath.row].description) 
} 

我不知道爲什麼表格有點滯後,當我滾動時跳躍。

回答

0

如果您確定滯後是由heightforRowAtIndexPath引起的,那麼爲什麼不計算每個單元格數據/索引路徑的高度,只有一次,當圖像更改時?

你應該只是返回dataController.Data [indexPath.row] .calculatedCellHeight或東西