【问题标题】:Firebase childrenCount into tableview labelFirebase childrenCount 进入 tableview 标签
【发布时间】:2016-08-28 08:35:01
【问题描述】:

我正在尝试将 Firebase childrenCount 作为 string 转换为 tableview label。它打印了所有内容,但由于某种原因它没有将它们放入标签中。

我做错了什么,你能说吗?

我使用snapshot.childrenCountcellForRowAtIndexPath 内部实现这一点:

let ref = FIRDatabase.database().reference().child("Snuses").queryOrderedByChild("Brand").queryEqualToValue(brands[indexPath.row]) 
                        print(snapshot.childrenCount)
                        snusProductCountLabel.text = snapshot.childrenCount as? String

                    }
                }
            })

这是我滚动时控制台的输出:

7
3
8
3
26
5
5
1
8
3
10

【问题讨论】:

  • 给出包含此节点的 JSON 树 Snuses ..
  • @Dravidian 检查我的编辑。

标签: swift uitableview firebase firebase-realtime-database


【解决方案1】:

我一定很笨。我通过将UInt 转换为Int 然后在标签String(count) 中解决它,如下所示:

let ref = FIRDatabase.database().reference().child("Snuses").queryOrderedByChild("Brand").queryEqualToValue(brands[indexPath.row])

        print(snapshot.childrenCount)
        var count: Int = Int(snapshot.childrenCount)
        snusProductCountLabel.text = String(count)

         }
     }
})

唯一的问题是标签在滚动时不断变化。但我尝试使用dispatch_a_sync

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    相关资源
    最近更新 更多