带有UITableView单元格的Swift 4 AlamofireImage

编程入门 行业动态 更新时间:2024-10-05 21:19:20
本文介绍了带有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("xxxxxxx/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

本文发布于:2023-11-26 18:54:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634778.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元格   UITableView   AlamofireImage   Swift

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!