【问题标题】:How can I load an image to a UIImageView如何将图像加载到 UIImageView
【发布时间】:2020-10-02 21:26:40
【问题描述】:

我希望在我的 Firebase 存储中搜索以我的用户 UID 命名的图像,然后将该图像显示在 UIImageView 中。这目前不起作用,我不确定为什么。任何答案将不胜感激。

@IBOutlet weak var picture: UIImageView!



override func viewDidLoad() {
    super.viewDidLoad()
    getUserInfo()
    downloadProfilePicture()


}

func downloadProfilePicture() {
let userID = Auth.auth().currentUser?.uid
let profilePicture = Storage.storage().reference().child("ProfilePictures").child(userID!)
profilePicture.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
    if let error = error {
        print("An error was encountered")
    } else {
        self.picture.image = UIImage(named: userID!)
        }
    }
}

【问题讨论】:

    标签: swift firebase firebase-storage swift5


    【解决方案1】:

    嗯……这很尴尬。

    func downloadProfilePicture() {
    let userID = Auth.auth().currentUser?.uid
    let profilePicture = Storage.storage().reference().child("ProfilePictures").child(userID!)
    profilePicture.getData(maxSize: 1 * 1024 * 1024) { (data, error) in
        if let error = error {
            print("An error was encountered")
        } else {
            self.picture.image = UIImage(data: data!)
            }
        }
    }
    

    Firebase 文档帮助我解决了这个问题 in the "Download" section of Storage。想想我的脸,手掌。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      相关资源
      最近更新 更多