2017-07-27 103 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
相关问题