Я учусь разрабатывать приложение iOS, и в моем первом приложении у меня есть tableView, который должен отображать данные из FirebaseDatabase.
Ниже приведена структура базы данных:
Ниже приведен код из viewcontroler.swift
import UIKit
import Firebase
class ctrTableViewController: UITableViewController {
var _ctrsArray = [String]()
var dbref = Database.database().reference()
let deviceID = UIDevice.init().identifierForVendor
func loadCtrs() {
// Load ctrs from DB to Tableview
dbref.child("\(String(describing: deviceID))/ctrs").observeSingleEvent(of: .value, with: { snapshot in
if let ctrs = snapshot.value as? [String: Any] {
for (ctr, _) in ctrs {
self._ctrsArray.append(ctr)
self.tableView.reloadData()
}
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
loadCtrs()
self.navigationItem.leftBarButtonItem = self.editButtonItem
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return _ctrsArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ctrCell")
cell?.textLabel?.text = _ctrsArray[indexPath.row]
return cell!
}
}
Что мне не хватает? TIA за всю вашу помощь.