我正在尝试使用firebaseui将图像加载到集合视图中遵循此模式。由于某种原因,默认图像已加载,但是我在Google存储中引用的图像从未出现。当我查看参考文献时,它们似乎都是正确的,但是图像仍然不会加载到图像视图中。这是我的视图控制器:
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
}
}
我的猜测是与正在加载的默认图像有关,但是一旦下载了新图像,视图就不会刷新。
它在其标题中出现图像没有" .jpg",因此当我用" .jpg"扩展名引用它时,没有找到它它。从参考中删除.jpg"已解决我的问题。