对于我正在处理的iOS项目,我使用Firebase作为数据库。我有多个页面,每个页面都有自己的参考,它们工作正常。但是,当我创建最新页面时,该应用程序运行时不会加载任何内容。 tableview是空白的,但是没有错误消息。我引用数据库的方式有问题吗?
代码如下:
import UIKit
import Firebase
class wrestlingController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var ref = DatabaseReference()
var wDate = [String]()
var wTime = [String]()
var wMatch = [String]()
var databaseHandle:DatabaseHandle = 0
var databaseHandle2:DatabaseHandle = 0
var databaseHandle3:DatabaseHandle = 0
@IBOutlet var wrestlingTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
ref = Database.database().reference()
databaseHandle = ref.child("Wrestle").child("wDates").observe(.childAdded) { (snapshot) in
let post = snapshot.value as? String
if let actualPost = post {
self.wDate.append(actualPost)
}
}
databaseHandle2 = ref.child("Wrestle").child("wTimes").observe(.childAdded) { (snapshot) in
let post2 = snapshot.value as? String
if let actualPost2 = post2{
self.wTime.append(actualPost2)
}
}
databaseHandle3 = ref.child("Wrestle").child("wMatches").observe(.childAdded) { (snapshot) in
let post3 = snapshot.value as? String
if let actualPost3 = post3 {
self.wMatch.append(actualPost3)
self.wrestlingTable.reloadData()
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return wMatch.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let wrestlingCell = tableView.dequeueReusableCell(withIdentifier: "wrestlingCell") as! wrestlingCell
wrestlingCell.wDate.text = wDate[indexPath.row]
wrestlingCell.wTime.text = wTime[indexPath.row]
wrestlingCell.wMatch.text = wMatch[indexPath.row]
return(wrestlingCell)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}