你好所有m从firebase检索数据但是我得到的错误我不知道从哪里来的coz打印出来给我的数据但是当它回到标签时它给我错误。希望得到帮助。谢谢。
代码:
import UIKit
import FirebaseDatabase
import Firebase
import FirebaseAuth
class ProfileViewController: UIPageViewController
{
@IBOutlet weak var profileimageview: UIImageView!
@IBOutlet weak var usernameText: UILabel!
@IBOutlet weak var displaynameText: UILabel!
var databaseref:DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
databaseref = Database.database().reference()
if let userID = Auth.auth().currentUser?.uid {
databaseref.child("profile").child(userID).observeSingleEvent(of: .value, with: { (snapshot) in
let dictionary = snapshot.value as? NSDictionary
let username = dictionary?["username"] as? String ?? "username"
print(username)
if let profileImageURL = dictionary?["photo"] as? String{
let url = URL(string: profileImageURL)
URLSession.shared.dataTask(with: url!, completionHandler: { (data, response, error) in
if error != nil{
print(error!)
return
}
DispatchQueue.main.async {
self.profileimageview.image = UIImage(data: data!)
}
}).resume()
}
self.usernameText.text = username
self.displaynameText.text = username
}) { (error) in
print(error.localizedDescription)
return
}
}
}
}
这是我的控制台:**注意 youandme是我打印出的价值**
youandme
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
在
中收到此错误self.usernameText.text = username
self.displaynameText.text = username