Я пытаюсь добавить и изображение в ячейку collectionView, если файл, связанный с ячейкой, находится на устройстве.Добавить изображение в collectionView Cell, если файл существует
Файл указан таким образом, что код ниже отображает изображение, однако я получаю сообщение об ошибке, которое он нашел, но пытается развернуть необязательный.
любые идеи, что не так с кодом?
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)
изображение "загрузить" в кассете.
Где находится "cell"? – BallpointBen
Что говорит крах? Большинство деталей на этом было бы полезно. – raidfive
Я не вижу никакой переменной 'cell', определенной в вашем методе. Вы забыли переубедить камеру? 'let cell = collectionView.dequeueReusableCell (withReuseIdentifier: reuseIdentifier, для: indexPath);' – ilbesculpi