OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 FirebaseUI 和存储引用加载图像 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:46
标题: ios - 使用 FirebaseUI 和存储引用加载图像

我正在尝试使用 FirebaseUI 将图像加载到 Collection View 中 following this pattern .出于某种原因,加载了默认图像,但是我在 Google 存储中引用的图像永远不会出现。当我查看引用资料时,它们似乎都是正确的,但图像仍然不会加载到 ImageView 中。这是我的 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

    }
}

我的猜测是它与正在加载的默认图像有关,但是一旦下载了新图像, View 就不会刷新。



Best Answer-推荐答案


Google 存储上的图片的标题中似乎没有“.jpg”,所以当我在末尾使用“.jpg”扩展名引用它时,它没有找到它。从引用中删除“.jpg”解决了我的问题。

关于ios - 使用 FirebaseUI 和存储引用加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44273257/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4