Load/Download 图片来自 SDWebimage 并显示在 Custom tableView cell imageView 中

Load/Download image from SDWebimage and display in Custom tableView cell imageView

我已经解析了其他值但是我将如何向 imageView 显示图像我已经在 Swift.I 中使用 SdWebImage 想要在底部单元格中显示它 "detail" 下面是我的代码

import UIKit
import SystemConfiguration
import MBProgressHUD


public struct Section {
    var arrayDataTop: String
    var arrayTerms: String
    var qrImage:String
    var collapsed: Bool

    public init( arrayDataTop: String,qrImage: String ,arrayTerms: String, collapsed: Bool = false) {
        self.arrayDataTop = arrayDataTop
        self.qrImage = qrImage
        self.arrayTerms = arrayTerms
        self.collapsed = collapsed
    }
}

class CollapsibleViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var tableViewCollapsible:UITableView!
@IBOutlet weak var listImage:UIImageView!

var nodatastr:String = "No Deal Found."
var dealIDCollapsible : String?
var dealDictCollapsible = [String: AnyObject]()
var parentNavigationController: UINavigationController?
private var loadingView:MBProgressHUD?

var sectionDataObj = [Section]()


override func viewDidLoad() {
    super.viewDidLoad()

    if (!self.isInternetAvailable()){

        self.alertMessageShow(title: "No Internet Connection", message: "Make sure your device is connected to the internet.")
    }
    else{
        if self.loadingView == nil {
            self.loadingView =  MBProgressHUD.showAdded(to: self.view, animated: true)
        }


        tableViewCollapsible.estimatedRowHeight = 100.0
        tableViewCollapsible.layoutIfNeeded()
        tableViewCollapsible.updateConstraintsIfNeeded()
        tableViewCollapsible.tableFooterView = UIView()


        self.listImageFetch()
        dealFetchParticularListing()
    }
}








func dealFetchParticularListing(){

    let prs = [
        "listing_id":dealIDCollapsible,//dealIDCollapsible,
        "Deal_fetch_listing": "1" as String
    ]
    Service.CreateDeal(prs as [String : AnyObject]?, onCompletion: { result in
        let json = result as? NSDictionary
        if let data = json as? [String:Any]{
            if let err = data["status"] as? String, err == "success"{
                if let data = data["result"] as? [Any]{
                    //
                    //fill your data in that local Section obj
                    //
                    var sectionDataObj = [Section]()
                    for sectionObj in data{
                        if let sectionObjVal = sectionObj as? [String:Any]{
                            if let qrcode = sectionObjVal["qrcode"] as? String{
                                if let tnc = sectionObjVal["tnc"] as? String{
                                    if let deal_title = sectionObjVal["deal_title"] as? String{
                                        let sectionValue = Section(arrayDataTop: deal_title, qrImage: qrcode, arrayTerms: tnc)
                                        // access main objects/UIelement on main thread ONLY
                                        sectionDataObj.append(sectionValue)

                                    }
                                }
                            }
                        }
                    }
                    DispatchQueue.main.async { () -> Void in
                        self.sectionDataObj.removeAll()
                        //
                        //assign ur data in main sampleData(Section obj) then reload tableView with that data.
                        //
                        self.sectionDataObj = sectionDataObj
                        self.tableViewCollapsible.reloadData()
                        self.loadingView?.hide(true)
                    }
                }
            }
        }
    })
}

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


    // Header
    if indexPath.row == 0 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "header") as! MyCellData
        cell.lblDealTitle.text = sectionDataObj[indexPath.section].arrayDataTop
        return cell
    }
    // Cell
    let cell = tableView.dequeueReusableCell(withIdentifier: "detail") as! MyCellData
    cell.lblTerm.text = sectionDataObj[indexPath.section].arrayTerms
    // here i want to show image 
    return cell
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension//320.0
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.row == 0 {
        let collapsed = !sectionDataObj[indexPath.section].collapsed
        // Toggle collapse
        sectionDataObj[indexPath.section].collapsed = collapsed
        self.tableViewCollapsible.reloadSections([indexPath.section], with: .automatic)
    }
}
 }



class MyCellData:UITableViewCell{

    @IBOutlet weak var lblDealTitle: UILabel!
    @IBOutlet weak var dealimage: UIImageView!
    @IBOutlet weak var lblTerm: UILabel!
    @IBOutlet weak var qrCodeImage: UIImageView!

}

Plz 帮助我 this.thanks 在 advance.All 一切正常我能够看到其他 details.Help 将 appreciated.Plz 帮助我我正在努力解决这个问题。

像这样更新你的 tableView cellForRowAt 以显示来自你的 sectionDataObj

的图像或你的单元格
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


    // Header
    if indexPath.row == 0 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "header") as! MyCellData
        cell.lblDealTitle.text = sectionDataObj[indexPath.section].arrayDataTop
        return cell
    }
    // Cell
    let cell = tableView.dequeueReusableCell(withIdentifier: "detail") as! MyCellData
    cell.lblTerm.text = sectionDataObj[indexPath.section].arrayTerms
    let imgUrl = sectionDataObj[indexPath.section]. qrImage
    cell.qrCodeImage.sd_setImage(with: URL(string:imgUrl), completed: nil)
    return cell
}