Reputation: 23
I have an UICollectionView
that starts hidden in the viewDidLoad
, then when an image is added with the UIImagePicker
delegate the collection goes "unhidden" and then reloads, here is the code below
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
self.imagesToSend.append(pickedImage)
}
self.imagenesCollectionView.isHidden = false
self.imagenesCollectionView.reloadData()
dismiss(animated: true, completion:nil)
}
the problem is that when the collection shows it doesn't show any image, I have to add a second image so the image can show, I want the collection to show when there are images and to hide when there aren't images, until now the hiding functionality its working fine, but not the showing one.
Upvotes: 2
Views: 148
Reputation: 355
Try to use the methods setNeedsLayout
or setNeedsDisplay
. They are related to the view update, and maybe you need to use them on the collectionView or on the imageView itself.
Upvotes: 0
Reputation: 1243
Try adding
self.imagenesCollectionView.isHidden = false
self.imagenesCollectionView.reloadData()
in dismiss completion handler. Like
dismiss(animated: true, completion:{
self.imagenesCollectionView.isHidden = false
self.imagenesCollectionView.reloadData()
})
Edit 1:
Instead of reloading collection view in completion. add collection view reload in viewWillAppear
method based on the array data availability.
eg:
if self.imagesToSend.count > 0 {
self.imagenesCollectionView.isHidden = false
self.imagenesCollectionView.reloadData()
} else {
self.imagenesCollectionView.isHidden = true
}
Upvotes: 1