セルに関連付けられたファイルがデバイスにある場合、コレクションビューのセルに追加してイメージを追加しようとしています。コレクションビューに画像を追加ファイルが存在する場合はセル
ファイルがあるので、以下のコードでイメージが表示されますが、オプションでアンラップしようとするとエラーが発生します。
コードに問題がありますか?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: JourneyCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! JourneyCollectionViewCell
// query if file is on LDS and add image to indicate
let cellPartName = self.partArray[indexPath.item].name
let checkQuery = PFQuery(className: "downloadedAudio")
checkQuery.whereKeyExists(cellPartName)
checkQuery.fromLocalDatastore()
checkQuery.getFirstObjectInBackground(block: { (object, error) in
if error != nil || object == nil {
print("The file does not exist locally on the device, hide the image.")
//cell.ImageDownloaded.image = UIImage(named: "")
// crashes on this line
cell.ImageDownloaded.isHidden = true
} else {
print("the file already exists on the device, show the image.")
//cell.ImageDownloaded.image = UIImage(named: "download")
// crashes on this line
cell.ImageDownloaded.isHidden = false
}
})
return cell
}
the file already exists on the device, show the image.
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
画像 "ダウンロード" のカセットです。
「セル」はどこに定義されていますか? – BallpointBen
クラッシュは何を言いますか?それについてのほとんどの詳細が役に立つでしょう。 – raidfive
あなたのメソッド内で 'cell'変数が定義されていないようです。あなたはセルをデキューするのを忘れましたか? 'cell = collectionView.dequeueReusableCell(withReleaseIdentifier:reuseIdentifier、for:indexPath);' – ilbesculpi