Kind of an odd question but I've been making a quiz app and am storing the quiz data in Firebase Firestore. I can not seem to figure out how to load the quiz data into my static table view. The quiz question table view controller consists of two static table view sections, the first being one cell for the actual question, and the second being 4 cells for each answer choice. All the tutorials for Firestore seem to be using dynamic table views to load their data in.. Has anyone who worked with Firebase Firestore worked around this or has advice? Thanks.
Code for reference:
import UIKit
import Firebase
class QuestionTableViewController: UITableViewController {
@IBOutlet weak var questionCell: UITableViewCell!
@IBOutlet weak var optionCellA: UITableViewCell!
@IBOutlet weak var optionCellB: UITableViewCell!
@IBOutlet weak var optionCellC: UITableViewCell!
@IBOutlet weak var optionCellD: UITableViewCell!
var questionArray = [Question]()
var db: Firestore!
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Question"
navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil)
tableView.sectionHeaderHeight = 50
tableView.tableFooterView = UIView()
db = Firestore.firestore()
loadData()
}
func loadData() {
db.collection("QuestionBank").getDocuments() {
querySnapshot, error in
if let error = error {
print("\(error.localizedDescription)")
} else {
self.questionArray = querySnapshot!.documents.compactMap({Question(dictionary: $0.data())})
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let controller = ResultsViewController()
navigationController?.pushViewController(controller, animated: true)
}
}