本文介绍了带有UITableView单元格的Swift 4 AlamofireImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用AlamofireImages尝试从服务器下载图像并将其显示在表格视图单元格中,这是我得到的,但是我的图像没有出现,只是textLabel和detailTextLabel

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 and detailTextLabel

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

        let cell = tableView.dequeueReusableCell(withIdentifier: "trendingCell", for: indexPath)

        print(self.array[indexPath.row])

        cell.textLabel?.text = (self.array[indexPath.row]["title"] as! String)

        cell.detailTextLabel?.text = (self.array[indexPath.row]["username"] as! String)

        Alamofire.request("http://xxxxxxx.com/uploads/" + (self.array[indexPath.row]["cover"] as! String)).responseImage { response in
            if let image = response.result.value {
                cell.imageView?.image = image
            }
        }

        return cell
    }


推荐答案

尝试以下操作:

 Alamofire.request(imageUrl!, method: .get).response { response in
                    guard let image = UIImage(data:response.data!) else {
                        // Handle error
                        return
                    }
                    let imageData = UIImageJPEGRepresentation(image,1.0)
                    cell.myImage.image = UIImage(data : imageData!)
                }

这对我来说很好。.
希望这会有所帮助。

This works fine for me..Hope This will helpful.

这篇关于带有UITableView单元格的Swift 4 AlamofireImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:58