Swift 4 AlamofireImage with UITableView Cell

后端 未结 10 3270
梦如初夏
梦如初夏 2021-02-20 12:56

I am using AlamofireImages to try to download an image from a server and display it in my table view cell, this is what I got, but my images does not appear, just the textLabel

10条回答
  •  时光取名叫无心
    2021-02-20 13:45

    Swift-5 Supported Code That Work Perfectly

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
        let cell = tblView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
        cell.lblName.text = arrData[indexPath.row]["name"] as? String
    
      let imageUrl = arrData[indexPath.row]["imageUrl"] as? String
    
        Alamofire.request(imageUrl!, method: .get).response { response in
            guard let image = UIImage(data:response.data!) else {
                // Handle error
                return
            }
            let imageData = image.jpegData(compressionQuality: 1.0)
            cell.imgCourses.image = UIImage(data : imageData!)
        }
    
        return cell
    } 
    

提交回复
热议问题