enter image description here我正在尝试使用 swift 4 创建基于购物车的应用,在表视图中显示来自oData的产品列表,odata的元素之一包含Image的URL
使用以下代码我试图在picUrl变量中生成URL
var picUrl = String()
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ContactCell", for: indexPath) as! FUIContactCell
let product = self.entities[indexPath.row]
picUrl = ("https://\(self.hurl)\(product.pictureUrl! as String)" )
if let url = URL(string: picUrl){
downloadImage(url: url)
}
cell.detailImage = #imageLiteral(resourceName: "Image.png")
cell.detailImage = self.imageView.glyphImage
func getDataFromUrl(url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
URLSession.shared.dataTask(with: url) { data, response, error in
completion(data, response, error)
}.resume()
}
func downloadImage(url: URL) {
//print("Download Started")
getDataFromUrl(url: url) { data, response, error in
// guard let data = data, error == nil else { return }
print(response?.suggestedFilename ?? url.lastPathComponent)
print("Download Finished")
DispatchQueue.main.async() {
self.imageView = (UIImage(data: data!))!
}
}
}
downloadImage(url:url)从url调用图像。
但不知怎的,我收到错误enter image description here