2017-07-27 101 views
0

我想解決這個真的很慢,緩慢滾動在我的桌子上。慢速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 

     } 
    } 
} 
+0

你不應該獲取這樣的從'CoreData'數據之前獲取的圖像。如果你在'cellForRowAt'中獲取它,每次單元被重用時它都會獲取數據。您最好在UITableView代表鏈之外獲取數據。如'viewDidLoad'。 – Ryan

回答

0

有兩種解決方法

  1. 在使用異步的背景中獲取和設置圖像。

  2. 重裝泰伯維數據

0

tone.image做懶惰的獲取?我沒有使用AERecord,但如果延遲加載,那麼可能是是一個昂貴的操作。

你是否試過在後臺線程上執行該操作,所以主線程沒有被阻塞?

我會很想試試這個:

  1. 通過tone對象插入到mwCellTableViewCell
  2. mwCellTableViewCell試圖讓tone.image在後臺線程
  3. 時調用返回,跳回上主線和套self.image = toneImage
相關問題