gpt4 book ai didi

swift - Firebase ChildrenCount 计入 tableview 标签

转载 作者:行者123 更新时间:2023-11-30 13:07:16 27 4
gpt4 key购买 nike

我正在尝试将 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

最佳答案

我一定是个傻子。我通过将 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

关于swift - Firebase ChildrenCount 计入 tableview 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39189404/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com