swift - 使用 alamofireimage 在 UIImageview 中显示图像

标签 swift alamofire swift4 alamofireimage

这似乎是一个愚蠢的问题,但我对 Swift 还很陌生。

我想从 https://httpbin.org/image/png 下载 PNG 图像并让它显示在我的 UIImageView 中,它的名称为 imageView,但它不起作用。

[Result]: SUCCESS: , {33.333333333333336, 33.333333333333336} [Timeline]: Timeline: { "Request Start Time": 527346831.982, "Initial Response Time": 527346833.435, "Request Completed Time": 527346833.437, "Serialization Completed Time": 527346833.468, "Latency": 1.453 secs, "Request Duration": 1.455 secs, "Serialization Duration": 0.031 secs, "Total Duration": 1.486 secs } SUCCESS: , {33.333333333333336, 33.333333333333336} image downloaded: , {33.333333333333336, 33.333333333333336}

import UIKit
import Alamofire
import AlamofireImage

class ViewController: UIViewController {

@IBOutlet weak var imageView: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()


    Alamofire.request("https://httpbin.org/image/png").responseImage { response in
        debugPrint(response)

        debugPrint(response.result)

        if let imageView = response.result.value {
            print("image downloaded: \(imageView)")


        }
    }     
}
}

最佳答案

您没有将图像设置为您的 imageViewimage。这是您的代码,已修复:

Alamofire.request("https://httpbin.org/image/png").responseImage { response in
    if let image = response.result.value {
        self.imageView.image = image
    }
} 

关于swift - 使用 alamofireimage 在 UIImageview 中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46264574/

相关文章:

ios - Alamofire 5 委托(delegate)中缺少 sessionDidReceiveChallenge

ios - 带有 IBOutlet 集合的 UIViewController 类仍然与不再存在的 Storyboard有联系

ios - NSOperation 取消和 NSOperationQueue

ios - 如何自定义单元格背景

json - 用于解析 JSON 并返回字典数组的 Swift 函数

json - Swift 4 JSONSerialization.jsonObject

ios - Swift 中的 import 语句是否有相关成本?

ios - 在 iOS 测试中以编程方式模拟 GPS 位置

ios - 错误: "No such module" for cocoa pod framework

swift - RX Alamofire Swift 空响应 JSON