【问题标题】:Cannot Access Firebase Snap Data无法访问 Firebase 快照数据
【发布时间】:2017-07-27 03:59:39
【问题描述】:

我的 firebase 结构设置如下:

每个键都包含我想用来填充 UICollectionView 的数据。但是,我在访问 Firebase 数据时遇到了困难。在Android中,我使用了类似于

的方法
dataSnapshot.child("xxx").getValue()

但是,这种类型的可访问性在 iOS 中似乎不可用。以下是我正在尝试的方法:

     self.dataSource = self.collectionView?.bind(to: self.ref.child("Polls")) { collectionView, indexPath, snap in
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PollCell
        /* populate cell */
        cell.pollQuestion.text = snap.child("question").getvalue
          print(indexPath)

        return cell
    }

我收到一条错误消息,指出“FIRDataSnapshot”类型的值没有子成员

【问题讨论】:

    标签: ios swift firebase firebase-realtime-database firebaseui


    【解决方案1】:

    如果你在 Android 上有这条线:

    dataSnapshot.child("xxx").getValue()
    

    在 iOS 上是:

    snapshot.childSnapshot(forPath: "xxx").value
    

    对于此类问题,我强烈建议使用 Firebase 参考文档:https://firebase.google.com/docs/reference/ios/firebasedatabase/api/reference/Classes/FIRDataSnapshot#-childsnapshotforpathFIRDataSnapshot 中的方法数量并不多,它可以让您更快地取得进展。

    【讨论】:

    • 非常感谢弗兰克
    猜你喜欢
    • 2017-01-30
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2016-04-09
    • 1970-01-01
    • 2020-06-21
    • 2020-06-11
    • 2017-01-30
    相关资源
    最近更新 更多