【发布时间】:2017-02-02 06:45:39
【问题描述】:
使用 Alamofire 下载或使用 URL 转换为数据对象并将数据对象转换为 UIImage 时,UIImageView 图像无法加载。我在 UITableViewCells 上的图像正在工作,但 UIImageviews 在 UIView 中却不是独立的。它给了我一个空白。
UIImageViews:它们是 UIView 的子视图,它是 UITableView 的子视图
这是我使用的代码:
let imageURL = URL(string: _imageUrl)
let imageData = try? Data(contentsOf: imageURL!)
imageView.image = UIImage(data: imageData!)
这是我在 Alamofire 中使用的扩展:
extension UIImageView {
func donwloadImageFrom(_ imageURL: String, contentMode: UIViewContentMode) {
let stringUrl = URL(string: imageURL)!
Alamofire.request(stringUrl, method: .get).response(completionHandler: { response in
if let imageData = response.data {
DispatchQueue.main.async(execute: {
self.contentMode = contentMode
self.image = UIImage(data: imageData)
})
}
})
}
}
【问题讨论】:
-
我也有同样的问题。首先,我认为这与我正在使用的图像加载库有关,但是。直接加载网址似乎也不起作用
-
我在question找到了答案
标签: uiimageview uiimage alamofire ios10 xcode8