ios - 如何在不同 View 之间共享从 firebase 存储下载的图像?

标签 ios swift firebase-realtime-database firebase-storage

这是我用来从存储中获取图像的代码。它像魅力一样工作,但我不想再次在不同的 View 上重新下载它。

func retreiveImagesFromFireBase(downloadUrl:String,imageHolder:UIImageView){
    if downloadUrl != "" {
        let storageRef = Storage.storage().reference(forURL: downloadUrl)
        // Download the data, assuming a max size of 1MB (you can change this as necessary)
        storageRef.getData(maxSize: 5*1024*1024) { (data, error) in
            if error == nil {
                if let pic = UIImage(data: data!) {
                    imageHolder.image = pic
                }
            } else {
                print(error)
            }
        }
    }
}

我该如何处理?

最佳答案

如果你只有一两张图片,那么只需存储在 userdefault 中,然后你就可以在任何 viewController 中访问,将 image 存储为 datauserdefault 中 每当你想使用时,只需将数据转换为图像并使用它,请参见以下代码将数据转换为图像

let image = UIImage(data: imageData)

关于ios - 如何在不同 View 之间共享从 firebase 存储下载的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54923671/

相关文章:

ios - 安装Xcode 5.1后报错: Two views in the same hierarchy have the same restoration identifier

ios - Storekit 和处理已购买 IAP 的用户

ios - 存储 .p12 文件并在 iOS 应用程序中实现 SSL

android - 如何实现 SetOnItemClickListener FirebaseRecyclerViewAdapter

reactjs - Firebase onCreate 向 auth.user 添加自定义声明

iphone - 在 UIPicker 中显示 CSV 文件的内容

javascript - 下载网页并在连接可用时刷新它

ios - 如何在 Swift/Xcode 中删除 PhysicsBody 轮廓

Swift:AppDelegate 中 AppStart 处的网络请求 - ViewController 中的 CompletionHandler?

ios - 如何将按钮添加到 tableview,以便它提取特定于按下它的单元格的用户数据?