ios - 从 Firebase child 获取数据到 Xcode 8 swift 3 ios 10+ 中的标签

标签 ios swift firebase firebase-realtime-database

我想将 Firebase 数据显示到 UICollection View 中的标签。 enter image description here

我看过很多教程并在 stackoverflow 上发现了类似的问题,但我对这种和平的代码有点困惑。请帮我找到并纠正错误

     var ref = FIRDatabase.database().reference()

    ref.observeSingleEvent(of: .value, with: { snapshot in
        let m = snapshot.value.objectForKey("AddedInfo/Product")as?
        self.EmailLabel.text = m
    })

最佳答案

不要读取整个数据库,只显示一个值。而是只读取您需要的值:

var ref = FIRDatabase.database().reference()
var productRef = ref.child("AddedInfo/Product")

ref.observeSingleEvent(of: .value, with: { snapshot in
    let m = snapshot.value as? String
    self.EmailLabel.text = m
})

关于ios - 从 Firebase child 获取数据到 Xcode 8 swift 3 ios 10+ 中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41544005/

相关文章:

ios - 更改 cellForRowAtIndexPath 中的 NSLayoutConstraint 常量不断导致 "unable to satisfy constraints"错误

ios - 如何创建横向和纵向的图像集?

安卓火力地堡 : how to change objects with specific field value?

javascript - 为什么它返回不同的结果? (es6箭头函数)

android - Firebase 仪表板不显示价格值

ios - EXC_BAD_ACCESS : When trying to handle touches event in parent UIVIew

ios - 旋转按钮标题标签文字

ios - 为什么这个从 NSString 得到的 NSDate 切换了月份?

ios - UIBarButtonItem 在 unwind segue 之后仍然被选中/突出显示

swift - 为什么 Realm 数据库属性值不改变?