【发布时间】:2017-05-07 18:26:45
【问题描述】:
我目前正在尝试仅显示从我的 firebase 数据库中提取的简单值到 TableView 中。我得到的问题是单元格当前没有填充任何内容。我已经输入了打印语句,只是为了确保数组不为空,而事实并非如此。我正在使用以下代码:
class DisplayTransactions: UITableViewController {
var ref = FIRDatabase.database().reference()
//gets current firebase users
var userC = FIRAuth.auth()?.currentUser
var pubCount: Int!
var anArray = [String] ()
override func viewDidLoad() {
super.viewDidLoad()
var transRef = FIRDatabase.database().reference().child("Users").child((userC?.uid)!).child("PaymentTransactions")
//for Deposit children
transRef.child("Deposit").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
//creates enumerator of the snapshot children for
let enumerator = snapshot.children
while let rest = enumerator.nextObject() as? FIRDataSnapshot {
self.anArray.append(String(rest.value))
//printing the rest.value to make sure there are children to iterate through
print(rest.value)
}
})
//for Withdrawl children
transRef.child("Withdraw").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
//creates enumerator of the snapshot children for
let enumerator = snapshot.children
while let rest = enumerator.nextObject() as? FIRDataSnapshot {
self.anArray.append(String(rest.value))
//printing the rest.value to make sure there are children to iterate through
print(rest.value)
}
})
print(anArray)
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return anArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "cellID")
cell.textLabel?.text = anArray[indexPath.row]
print(anArray[indexPath.row])
return cell
}
}
【问题讨论】:
标签: swift firebase firebase-realtime-database firebase-authentication