Вот моя база данных Firebase:
![enter image description here](https://i.stack.imgur.com/6M6jO.png)
А вот мой код:
class AdminSearchViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var ref: DatabaseReference!
var jobList = [jobModel2]()
@IBOutlet weak var tlb2: UITableView!
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! ViewController2TableViewCell
let job: jobModel2
job = jobList[indexPath.row]
cell.ship.text = job.consignee
cell.reference.text = job.reference
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return jobList.count
}
override func viewDidLoad() {
super.viewDidLoad()
if FirebaseApp.app() == nil {
FirebaseApp.configure()
}
Database.database().reference().child("jobs").observe(DataEventType.value) { (snapshot) in
if snapshot.childrenCount>0 {
self.jobList.removeAll()
for jobs in snapshot.children.allObjects as! [DataSnapshot]{
let jobObject = jobs.value as? [String: AnyObject]
let jobConsignee = jobObject?["consignee"]
let jobReference = jobObject?["reference"]
let job = jobModel2( consignee: jobConsignee as! String?,
reference: jobReference as! String?
)
self.jobList.append(job)
}
self.tlb2.reloadData()
}
}
}
}
Проблема, с которой я сталкиваюсь,что в моем TableView ничего не происходит, я думаю, что это связано с .childs, так как я думаю, что мне нужно сменить его с «рабочих мест» на что-то, но я не могу этого понять.
Я хочу отобразить список всех ссылок со всех UID, а не только один.
КОД, КОТОРЫЙ ПОКАЗЫВАЕТСЯ В ПЕЧАТИ:
func readJobs() {
let ref = Database.database().reference()
let ref1 = ref.child("jobs").queryOrderedByKey()
ref1.observeSingleEvent(of: .value, with: { snapshot in
let allUsersAndJobs = snapshot.children.allObjects as! [DataSnapshot]
for user in allUsersAndJobs {
let uid = user.key
print("user id: \(uid)")
let thisUsersJobs = user.children.allObjects as! [DataSnapshot]
for job in thisUsersJobs {
let jobKey = job.key
let consignee = job.childSnapshot(forPath: "consignee").value as! String
print(" job #: \(jobKey)")
print(" consignee: \(consignee)")
}
}
})
}