简体   繁体   中英

SDWebImage not loading images Until I scroll the tableView in Swift

If I scroll, then only the images are loading. Here is my code

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

You need to register the nib as a reusable cell for the UITableView:

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

Then in tableView's dataSource method 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM