1
私のアプリを起動すると、データベース内のすべての関係者の名前と場所のデータが表示されますが、表示されません。私は正しいデータを得ていると確信していますが、何が間違っているのか分かりません。新しいデータが追加されるたびに、すべてのデータを表示するようにテーブルを取得するにはどうすればよいですか?ここで私のUITableViewCellsが情報を表示しないのはなぜですか?
import UIKit
import Firebase
import FirebaseDatabase
class FindPartiesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var parties = [party]()
@IBOutlet weak var partyTable: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
partyTable.delegate = self
partyTable.dataSource = self
let ref = FIRDatabase.database().reference()
ref.child("parties").queryOrderedByKey().observe(.childAdded, with: {
snapshot in
let snapshotValue = snapshot.value as? NSDictionary
let name = snapshotValue?["name"] as! String
let location = snapshotValue?["location"] as! String
let description = snapshotValue?["description"] as! String
self.parties.append(party(name: name, description: description, location: location))
})
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// creates the number of cells in the table
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return parties.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// Make table cells the show the user name
var cell = partyTable.dequeueReusableCell(withIdentifier: "Cell")
let nameLabel = cell?.viewWithTag(1) as! UILabel
nameLabel.text = parties[indexPath.row].name
let locationLabel = cell?.viewWithTag(2) as! UILabel
locationLabel.text = parties[indexPath.row].location
return cell!
}
}
は私のデータベースのセットアップです:
testApp
parties
-KUUzxkssjWoSZ22QS8r
description: ""
location: "Here"
name: "party 1"
-KUV0ObFVbPyI_SJ0f3F
description: ""
location: "There"
name: "party 2"