简体   繁体   English

从Firebase数据库更新数组值

[英]update array value from firebase database

I have static tableview that return array count with this array 我有静态tableview返回与此数组的数组计数

var profiles = [
    Profile(title: "Email", description: "Add Email"),
    Profile(title: "Gender", description: "Add Gender"),
    Profile(title: "Location", description: "Add Location"),
    Profile(title: "About", description: "Add About")
]

I want to update the description from my array from the data I get from firebase database, but when I want to update it's not showing in controller this is my code 我想根据我从firebase数据库获得的数据更新数组中的描述,但是当我想要更新时,它不在控制器中显示,这是我的代码

fileprivate func updateUserProfile() {
    guard let uid = Auth.auth().currentUser?.uid else { return }

    Database.database().reference().child("users").child(uid).observeSingleEvent(of: .value, with: { (snapshot) in
        guard let value = snapshot.value as? [String: Any] else { return }

        guard let emailDescription = value["email"] as? String else { return }
        guard let genderDescription = value["gender"] as? String else { return}

        self.profiles[0].description = emailDescription
        self.profiles[1].description = genderDescription

    }) { (error) in
        print(error.localizedDescription)
    }
}

how can I update my array from firebase database? 如何从Firebase数据库更新阵列?

You should reload data after getting updated values from Firebase. 从Firebase获取更新后的值,您应该重新加载数据。 Put this in the observeSingleEvent completion: self.tableView.reloadData() 将其放在observeSingleEvent完成中: self.tableView.reloadData()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM