我嘗試獲取 Firebase 中的行數。而是cannot find counter in scope在線退貨柜臺上說的。
extension FourthTabFirstView: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let ref = database.child("placeID")
ref.observe(.value, with: { (snapshot: DataSnapshot!) in
print(snapshot.childrenCount)
let counter = snapshot.childrenCount
})
return counter
}
......
}
uj5u.com熱心網友回復:
1-宣告這個實體變數
var counter = 0
2-這應該在里面viewDidLoad
let ref = database.child("placeID")
ref.observe(.value, with: { [weak self] (snapshot: DataSnapshot!) in
print(snapshot.childrenCount)
self?.counter = snapshot.childrenCount
self?.tableView.reloadData()
})
3-改變numberOfRowsInSection
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return counter
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/479884.html
