1
Firebaseデータベース内の子値の数を含むテキスト文字列を表示するために、UIButtonタイトルテキストを実装しようとしています。 viewDidLoadで、firebaseデータベースに存在する "place"の子値の "#"を表示するボタンが必要です。以下のコードと火災データベースのデータモデルを参照してください。前もって感謝します!Firebaseからの子値のカウントを表示するUIButtonラベル
// JSON data model
{
"users" : {
"CmtuebwVrmOG3n4uSsIK1b4FsSN2" : {
"Places" : {
"-KhDwZJvca9HedFluJ5O" : {
"addedBy" : "CmtuebwVrmOG3n4uSsIK1b4FsSN2",
"place" : "Edinburgh, UK",
"timestamp" : 1.491678152020824E9
},
"-KhE7raDrM2RRs-N6FXg" : {
"addedBy" : "CmtuebwVrmOG3n4uSsIK1b4FsSN2",
"place" : "Hong Kong",
"timestamp" : 1.49168137667081E9
},
"-KhFUaEjjhE3RBOw95fc" : {
"addedBy" : "CmtuebwVrmOG3n4uSsIK1b4FsSN2",
"place" : "Illinois, USA",
"timestamp" : 1.491704112134812E9
},
"-Kk4EI1D7fuPyY2rvbdW" : {
"addedBy" : "CmtuebwVrmOG3n4uSsIK1b4FsSN2",
"place" : "Karnataka, India",
"timestamp" : 1.494736515236516E9
}
},
},
var placesTableView: PlacesTableVC?
var placeList = [Place]()
var placesDictionary = [String: Place]()
var tableViewCount: Int?
lazy var placesButton: UIButton = {
let customButton = UIButton()
customButton.backgroundColor = UIColor.blue
// display the number of place values from firebase in the button title text
customButton.setTitle("\(self.placesTableView?.placeList.count ?? 0) Visited Places", for: .normal)
customButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
customButton.setTitleColor(.white, for: .normal)
customButton.addTarget(self, action: #selector(handleShowPlacesVC), for: .touchUpInside)
return customButton
}()
あなたの問題は何ですか? – t4nhpt
こんにちは - UIButtonタイトルテキストに、Firebaseデータベース内に存在する子の値「場所」の数を表示する方法を知りたいです。たとえば、提供されているFirebaseのJSONには4つの「場所」の値がありますので、UIButtonのタイトルテキストに「4」を表示します。ありがとう! – user3708224