4 Replies
      Latest reply on Aug 11, 2019 10:05 AM by JLago
      JLago Level 1 Level 1 (0 points)

        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() {
                navigationItem.title = "Question"
                navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .plain, target: nil, action: nil)
                tableView.sectionHeaderHeight = 50
                tableView.tableFooterView = UIView()
                db = Firestore.firestore()
            func loadData() {
                db.collection("QuestionBank").getDocuments() {
                    querySnapshot, error in
                    if let error = error {
                    } else {
                        self.questionArray = querySnapshot!.documents.compactMap({Question(dictionary: $0.data())})
                        DispatchQueue.main.async {
            // 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)