我想解決這個真的很慢,緩慢滾動在我的桌子上。慢速Tableview與自定義單元格的圖像,Swift 3和核心數據
我使用核心數據封裝器AERecord獲取數據,並且它滾動而不cell.toneImage.image = UIImage(named: tone.image)
平滑的圖像是不是大(350 X 170),但DEF只要我滾動凍結用於第二足以加載新圖像。
我檢查了模擬器中的混合圖像等。它可能是數據被提取+同時加載圖像?任何想法或建議?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! mwCellTableViewCell
self.configureCell(cell, atIndexPath: indexPath)
return cell
}
func configureCell(_ cell: mwCellTableViewCell, atIndexPath indexPath: IndexPath) {
if let frc = fetchedResultsController {
if let tone = frc.object(at: indexPath) as? Tone {
// set data
cell.toneTitle.text = tone.name.uppercased()
let img:UIImage = tone.fav ? #imageLiteral(resourceName: "likeBtnOn") : #imageLiteral(resourceName: "likeBtnOff")
cell.favButton.setImage(img, for: .normal)
cell.favButton.tag = indexPath.row
cell.favButton.addTarget(self, action: #selector(favme(_:)), for: .touchUpInside)
cell.toneImage.image = UIImage(named: tone.image)
cell.toneImage.layer.cornerRadius = 8.0
cell.toneImage.clipsToBounds = true
}
}
}
你不應該獲取這樣的從'CoreData'數據之前獲取的圖像。如果你在'cellForRowAt'中獲取它,每次單元被重用時它都會獲取數據。您最好在UITableView代表鏈之外獲取數據。如'viewDidLoad'。 – Ryan