ライブラリから複数の画像を選択して、UICollectionView
で表示しようとしています。画像を取り込むときには問題なく動作しますが、画像はUICollectionView
に表示されません。私はもう一度イメージを選択しようとし、以前のイメージが表示されます。現在選択されているものはありません。ここでCollectionViewはDKImagePickerControllerでリロードしません
はコードです:ここでは
imagePicker.didSelectAssets = {[unowned self] (assets: [DKAsset]) in
print("Selected!")
for asset in assets {
asset.fetchOriginalImageWithCompleteBlock({ (image, info) in
guard let imageData = UIImageJPEGRepresentation(image!, 0) else {
print("There is no image bro..!")
return
}
let thumbnails = UIImage(data: imageData)
self.imageArray.append(thumbnails!)
print(image!)
})
}
self.collectionView.reloadData()
}
は私が問題を解決したか疑問に思う人のためcellForItemAt:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "selectedImage", for: indexPath) as! SelectedImageCell
cell.image = imageArray[indexPath.item]
return cell
}
です。ここにコードがあります。
let group = DispatchGroup()
for asset in assets {
group.enter()
asset.fetchOriginalImageWithCompleteBlock({ (image, info) in
guard let imageData = UIImageJPEGRepresentation(image!, 0) else {
print("There is no image bro..!")
return
}
let thumbnails = UIImage(data: imageData)
self.imageArray.append(thumbnails!)
print(image!)
group.leave()
})
}
group.notify(queue: .main, execute: {
print("finish..")
self.collectionView.reloadData()
})
コレクションのリロード後にforループ処理が終了したときに試してみます。 –
'cellForItemAt indexPath'メソッドを表示してください。 –
@ YogendraGiraseはすでに試しました。 – user3057414