SDWebImage不会加载图像,直到我在Swift中滚动tableView为止

问题描述 投票:-1回答:1

如果滚动,则仅加载图像。这是我的代码

  var nib: [Any] = Bundle.main.loadNibNamed("SampleTableViewCell", owner: self, options: nil)!
    let cell = nib[0] as? SampleTableViewCell
    let values = detailsArr[indexPath.row] as! SampleModel
    let url = URL(string: values.imageStr)
    cell?.title_Lbl.text = values.title
    cell?.desccription_Lbl.text = values.description
    cell?.image_View.sd_setImage(with: url)
    cell?.layoutIfNeeded()
    tableView.estimatedRowHeight = 370

    return cell!
}
ios swift uiimageview sdwebimage
1个回答
0
投票

您需要将笔尖注册为UITableView的可重用单元格:

let sampleNib = UINib(nibName: "SampleTableViewCell", bundle: nil)
tableView.register(sampleNib, forCellReuseIdentifier: "SampleTableViewCell")

然后在tableView的dataSource方法cellForRowAt中使它出队列:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

  let sampleCell = tableView.dequeueReusableCell(withIdentifier: "SampleTableViewCell") as! SampleTableViewCell

     /*
       Customise your cell here. 
       I suggest you make all your customisations inside the cell, and call here a function from the cell
       eg.:
       let values = detailsArr[indexPath.row] as! SampleModel
       sampleCell.setupCell(with: values) 
     */

  return sampleCell
}
© www.soinside.com 2019 - 2024. All rights reserved.