0
我試圖從URL顯示圖像到imageView。我在一個簡單的項目中使用同步方法成功完成了它。但是這個應用程序用於在線商店,所以我從JSON文件中獲取產品信息和圖像URL。我確信我已成功將所有數據存儲在產品陣列中。但我面臨的問題是:從快速顯示URL中的圖像,展開錯誤
fatal error: unexpectedly found nil while unwrapping an Optional value
這是代碼。
// UnWrapping imageURL
let url:NSURL? = NSURL(string: actualCurrentProduct.imageURL)
if let actualURL = url {
let imageData = NSData(contentsOfURL: actualURL)
if let actualImageData = imageData {
self.productImageView.image = UIImage(data: actualImageData)
}
}
它在此特定代碼中突出顯示。
self.productImageView.image = UIImage(data: actualImageData)
有人知道爲什麼嗎?真的很感激它。
爲me..check烏爾URL工作正常可能是導致這個問題。 – 2015-02-07 12:26:07
也許'self.productImageView'是'nil'? – rintaro 2015-02-07 12:59:53
@DharmeshKheni我檢查了網址,它的工作原理。 – mosesdw 2015-02-07 14:35:31