SDWebImage не загружает изображения, пока я не прокручиваю tableView в Swift - PullRequest
0 голосов
/ 21 января 2020

Если я прокручиваю, то загружаются только изображения. Вот мой код

  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!
}

1 Ответ

1 голос
/ 21 января 2020

Вам необходимо зарегистрировать перо как ячейку многократного использования для UITableView:

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

Затем в методе источника данных tableView cellForRowAt deque it:

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
}
...