菜鸟教程小白 发表于 2022-12-11 19:46:50

ios - 使用 FirebaseUI 和存储引用加载图像


                                            <p><p>我正在尝试使用 FirebaseUI 将图像加载到 Collection View 中
<a href="https://firebase.google.com/docs/storage/ios/download-files#downloading_images_with_firebaseui" rel="noreferrer noopener nofollow">following this pattern</a> .出于某种原因,加载了默认图像,但是我在 Google 存储中引用的图像永远不会出现。当我查看引用资料时,它们似乎都是正确的,但图像仍然不会加载到 ImageView 中。这是我的 ViewController :</p>

<pre><code>class EventViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

    @IBOutlet weak var postColView: UICollectionView!

    var posts: = []
    var event: Event!
    var ref = FIRDatabase.database().reference(withPath: &#34;post-items&#34;)

    override func viewWillAppear(_ animated: Bool) {

      ref.queryOrderedByKey().observe(.value, with: { snapshot in

            var newItems: = []

            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) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: &#34;Cell&#34;, for: indexPath) as! PostCell

      let imageView = cell.postImageView

      let picRef = FIRStorage.storage().reference().child(&#34;\(posts.imagePath!).jpg&#34;)


      print(picRef)
      imageView?.sd_setImage(with: picRef, placeholderImage: UIImage(named: &#34;IMG_2684&#34;))

      return cell

    }
}
</code></pre>

<p>我的猜测是它与正在加载的默认图像有关,但是一旦下载了新图像, View 就不会刷新。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>Google 存储上的图片的标题中似乎没有“.jpg”,所以当我在末尾使用“.jpg”扩展名引用它时,它没有找到它。从引用中删除“.jpg”解决了我的问题。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 使用 FirebaseUI 和存储引用加载图像,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/44273257/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/44273257/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 使用 FirebaseUI 和存储引用加载图像