Several questions here:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) - UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "dataCell", for: indexPath) as! GalleryImageCell
let asset = images[indexPath.row]
let ImageManager = PHImageManager.default()
if cell.tag != 0 {
ImageManager.cancelImageRequest(PHImageRequestID(cell.tag))
}
cell.tag = Int(ImageManager.requestImage(for: asset, targetSize: CGSize(width: 120, height: 120), contentMode: .aspectFill, options: nil, resultHandler: { (result, _) in
cell.galleryImage?.image = result
}))
return cell
}
line 6, are you sure the tag is 0 ?
should add a print to check:
if cell.tag != 0 {
ImageManager.cancelImageRequest(PHImageRequestID(cell.tag))
print("Exists, tag is", cell.tag)
}
result is optional.
Did you try to unwrap result
cell.tag = Int(ImageManager.requestImage(for: asset, targetSize: CGSize(width: 120, height: 120), contentMode: .aspectFill, options: nil, resultHandler: { (result, _) in
cell.galleryImage?.image = result ?? UIImage()
}))
Are you sure to get an image ?
To check, try to copy the image in a single UIImageView, to check you get some image.
Note:
var names should start with lowercase: imageManager vs ImageManager
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: