[英]Firebase childrenCount into tableview label
我正在嘗試將Firebase childrenCount
作為string
獲取到tableview
label
。 它打印出所有內容,但是由於某種原因,它沒有將它們放入標簽中。
我做錯了,你能說嗎?
我使用snapshot.childrenCount
在cellForRowAtIndexPath
內部實現了這一點:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.