ios - 找不到 downloadimageurl 来下载 Collection View 单元格图像的图像

标签 ios swift firebase uicollectionview

我陷入了一些可能非常简单的修复,但我似乎无法弄清楚。所以我正在开发一个类似 Instagram 的应用程序,目前正在设置 feed,youtube 上的一个人提供了一个关于如何设置 feed 的精彩视频。因此,我已经完成了该项目的大部分内容,并将其连接到 firebase,为帖子创建了一个 nsobject,其中包含 postID 和 pathToImage 的字符串。 Firebase 设置:http://imgur.com/a/nznr6并且有一个带有几个字符串的 post 对象类。我包含该图像是因为显示了很多可能不重要的代码这是我的 CollectionView 代码:

 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  return posts.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! UserFeedCollectionViewCell

 ->   cell.myImage. downloadImage(from: String)   <- does not exist, or doesn't show up. 
    cell.myImage.layer.cornerRadius = 12.0
    cell.myImage.clipsToBounds = true

    return cell
}

因此,如果您看到我无法让 downloadUrl 正常工作,而视频中的人能够通过自动完成功能完成此操作,请尽可能提供帮助。谢谢

最佳答案

例如,您可以使用 Kingfisher 来实现它。并且效果更好。 link 它还会缓存您的图像。

如何使用:添加从存储到数据库项目节点的图像链接。像这样:

enter image description here

然后用它来呈现和缓存图像。

示例:

 let imageView = UIImageView(frame: frame) // init with frame for example
 imageView.kf.setImage(with: <urlForYourImageFromFireBase>) //Using kf for caching images

在您的情况下,如果 cell.myImage 是 UIImageView:

cell.myImage.kf.setImage(with: <urlForYourImageFromFireBase>) //Using kf for caching images

希望对你有帮助

关于ios - 找不到 downloadimageurl 来下载 Collection View 单元格图像的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43715270/

相关文章:

ios - 如何以 24 小时格式获取日期

ios - 在 iOS 中使用 Microsoft App Center 环境变量

ios - 如果 App 因在代码中使用 UIWebView 而被拒绝,如何解决?

java - fragment 事务出错(空对象引用)

python - 如何从 Python 写入 GeoFire?

google-apps-script - 从 Firebase 读取数据...使用 Google Apps 脚本

ios - Xcode 分析错误,缺少库?

iphone - 如何知道ios通讯录是否可以访问Facebook联系人

ios - 在 AppDelegate Swift 中获取本地通知的正文或标识符

ios - Swift 选择器 - 发送到实例的无法识别的选择器