【发布时间】:2018-10-15 22:28:42
【问题描述】:
有人可以告诉我如何将 Firestore 中的数据附加到数组中吗?我想做的是这样当视图出现时,数据被附加到下面的数组中,然后附加到 tableView 的正确标签中。当我调用 print("(document.data())") 数据显示它应该在底部面板中执行的方式时,我只是不知道如何制作它以便它附加到我的数组中。任何帮助将不胜感激,非常感谢!
struct DetailsAdded {
var titleName: String
var detailsName: String
}
var array = [DetailsAdded]()
override func viewDidLoad() {
super.viewDidLoad()
db = Firestore.firestore()
loadData()
}
func loadData() {
db.collection("Users").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
print("\(document.data())")
}
}
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateWorkoutCell", for: indexPath) as! CreateWorkoutTableViewCell
cell.titleLabel.text = array[indexPath.row].titleName
cell.detailsLabel.text = array[indexPath.row].detailsName
return cell
}
【问题讨论】:
标签: swift uitableview append google-cloud-firestore