【发布时间】:2016-05-28 07:39:03
【问题描述】:
我正在尝试加载存储在 Firebase 服务器中的图像。我正在检查其他答案,但在能够打印正确的字符串值后我找不到为什么我得到零:
在我的应用程序中,我有以下数据结构:
这里是我用来加载它的代码(nil 值是评论中显示的值)
let profileDetailsRef = self.ref.childByAppendingPath("users/" + sessionUserID + "/details")
profileDetailsRef.observeEventType(.Value, withBlock: { snapshot in
self.txtUsername.text = sessionUserID
self.txtDisplayName.text = snapshot.value.objectForKey("nameToDisplay") as? String
let base64EncodedString = snapshot.value.objectForKey("userImage")! as! String
print(base64EncodedString) //Here it's printing well because I get the same value as shows in the dasboard so it finds it
//But the value "decodedData" here below is returning **nil**
let decodedData = NSData(base64EncodedString: base64EncodedString as! String, options: NSDataBase64DecodingOptions())
let decodedImage = UIImage(data: decodedData!)!
self.imageUserImage.image = decodedImage
}, withCancelBlock: { error in
print(error.description)
})
谢谢!
【问题讨论】: