【发布时间】:2020-05-03 20:49:00
【问题描述】:
所以我一直在尝试将一些 Firebase 数据放入 Swift 中的数组中,这样我就可以将其放入文本字段中。一切正常,但是,我的文本视图是空的,不包含行和数据。有谁知道为什么会这样?我的代码在下面(我在顶部导入了 Firebase 和 UIKit,不知道为什么 Stack Overflow 不让我把它放进去……抱歉):
class SummaryEmployeesFeelingViewController: UIViewController, UITableViewDataSource{
struct Feedback {
let id: Int
let feeling: String
let date: Timestamp
}
var feedbackarray = [Feedback]()
@IBOutlet weak var tableView: UITableView!
let summarydb = Firestore.firestore()
override func viewDidLoad() {
super.viewDidLoad()
addDatatoArray()
tableView.dataSource = self
tableView.tableFooterView = UIView()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return feedbackarray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let feedbackcell = tableView.dequeueReusableCell(withIdentifier: "CellReuseIdentifier")!
let text = feedbackarray[indexPath.row] as? String
feedbackcell.textLabel?.text = text
return feedbackcell
}
func addDatatoArray(){
summarydb.collection("employeefeedback").getDocuments { (snapshot, error) in
if error == nil && snapshot != nil{
for document in snapshot!.documents{
var idValue = document.get("id")
var feelingValue = document.get("feeling")
var dateValue = document.get("date")
let newEntry = Feedback(id: idValue as! Int, feeling: feelingValue as! String, date: dateValue as! Timestamp)
self.feedbackarray.append(newEntry)
}
}
}
}
}
谢谢!
【问题讨论】:
标签: ios arrays swift xcode firebase