Is the way of loading data from Firebase into a static table view different than a dynamic table view?

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)
    }
}

Replies

This is not the best forum for this question related to FireBase.


But, why do you want a static table instead of dynamic ?

didSelectRowAt does not seem to depend on the indexPath. Is it the case ? On purpose ?

Each quiz question has 4 answers in my app and I thought static table views are meant to be used when there is a predefined dataset like that.

Yea I have not finished that part yet. Right now if i select a cell in my quiz, it jumps to the ResultsController. I need to make it so it only pushes that controller when the quiz is done.