I am trying to load images into a collection view using FirebaseUI following this pattern. For some reason, the default images are loaded, but then the images I'm referencing in the Google Storage never appear. When I look at the references, they all appear to be correct, but the images still won't load into the image views. Here is my View Controller:
class EventViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
@IBOutlet weak var postColView: UICollectionView!
var posts: [Post] = []
var event: Event!
var ref = FIRDatabase.database().reference(withPath: "post-items")
override func viewWillAppear(_ animated: Bool) {
ref.queryOrderedByKey().observe(.value, with: { snapshot in
var newItems: [Post] = []
for item in snapshot.children {
let newPost = Post(snapshot: item as! FIRDataSnapshot)
newItems.append(newPost)
}
self.posts = newItems
self.postColView.reloadData()
})
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! PostCell
let imageView = cell.postImageView
let picRef = FIRStorage.storage().reference().child("\(posts[indexPath.row].imagePath!).jpg")
print(picRef)
imageView?.sd_setImage(with: picRef, placeholderImage: UIImage(named: "IMG_2684"))
return cell
}
}
My guess is it has something to do with the default images being loaded, but then the views not being refreshed once the new image is downloaded.