AFNetworking 中 "setImageWithURLRequest: placeholderImage: success:" 的 Alamofire 方式
Alamofire way for "setImageWithURLRequest: placeholderImage: success:" in AFNetworking
我正在尝试在集合视图中显示来自 url 的图像。到目前为止,我一直在为此使用 AFNetworking,但现在我正在转向 Alamofire。
我找不到像使用方法 'setImageWithURLRequest: placeholderImage: success:' 那样呈现图像的正确方法
我是否需要使用 AFNetworking 才能正确执行此操作?有没有我跳过的 Alamofire 方法?
提前致谢
编辑
我目前正在使用 AlamofireImage
这是我正在使用的代码:
Alamofire.request(.GET, urlString)
.responseImage { response in
if let image = response.result.value {
self.imageView.image = image
}
}
我的问题是这段代码在 'cellForItemAtIndexPath' 方法中,每次我滚动图像时都会一次又一次地重新充电。 AFNetworking
没有发生这种情况
您想在 Alamofire 中使用 UIImageView
扩展来设置来自 URL 的图像。 README.
中有一些非常详细的文档
let imageView = UIImageView(frame: frame)
let URL = NSURL(string: "https://httpbin.org/image/png")!
imageView.af_setImageWithURL(URL)
祝你好运!
我正在尝试在集合视图中显示来自 url 的图像。到目前为止,我一直在为此使用 AFNetworking,但现在我正在转向 Alamofire。 我找不到像使用方法 'setImageWithURLRequest: placeholderImage: success:' 那样呈现图像的正确方法 我是否需要使用 AFNetworking 才能正确执行此操作?有没有我跳过的 Alamofire 方法? 提前致谢
编辑 我目前正在使用 AlamofireImage 这是我正在使用的代码:
Alamofire.request(.GET, urlString)
.responseImage { response in
if let image = response.result.value {
self.imageView.image = image
}
}
我的问题是这段代码在 'cellForItemAtIndexPath' 方法中,每次我滚动图像时都会一次又一次地重新充电。 AFNetworking
没有发生这种情况您想在 Alamofire 中使用 UIImageView
扩展来设置来自 URL 的图像。 README.
let imageView = UIImageView(frame: frame)
let URL = NSURL(string: "https://httpbin.org/image/png")!
imageView.af_setImageWithURL(URL)
祝你好运!