title: Expandable table view cell (FAQ style)
body: <p>I have an FAQ style table view where each cell contains 2 UILabels - one for the question and one for the answer. For now, the question and the answer are shown on viewDidLoad(). Using the didSelectRowAt() method, I thought I could hide the answer UILabel when the cell is clicked but it doesn't seem to be working. Nothing changes on tapping the cell.</p>
  <p><a href="https://i.stack.imgur.com/WXF3j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WXF3j.png" alt="FAQ Table View Cell" /></a></p>
  <p>Code:</p>
  <pre><code>class FAQsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
      
      @IBOutlet weak var faqsTableView: UITableView!
      
      struct faqStructure {
          let question: String
          let answer: String
      }
      
      var faqsArray: [faqStructure] = []
      
      override func viewDidLoad() {
          
          faqsTableView.rowHeight = UITableView.automaticDimension
          faqsTableView.estimatedRowHeight = 600
          faqQuery()
      }
      
      @IBAction func dismiss(_ sender: UIButton) {
          dismiss(animated: true, completion: nil)
      }
      
      func faqQuery() {
          let faqsDB = Database.database().reference().child(&quot;FAQs&quot;)
          faqsDB.observe(.value, with: { (snapshot) in
              self.faqsArray.removeAll()
              for child in snapshot.children {
                  let faqSnapshot = child as! DataSnapshot
                  let faqQuestion = faqSnapshot.childSnapshot(forPath: &quot;Question&quot;).value as! String
                  let faqAnswer = faqSnapshot.childSnapshot(forPath: &quot;Answer&quot;).value as! String
                  self.faqsArray.append(.init(question: faqQuestion, answer: faqAnswer))
                  self.faqsTableView.reloadData()
              }
          })
      }
      
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return faqsArray.count
      }
      
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let faqItem = faqsTableView.dequeueReusableCell(withIdentifier: &quot;FAQ Cell&quot;) as! FAQsItemCell
          faqItem.questionLabel.text = faqsArray[indexPath.row].question
          faqItem.answerLabel.text = faqsArray[indexPath.row].answer
          
          return faqItem
      }
      
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          let faqItem = faqsTableView.dequeueReusableCell(withIdentifier: &quot;FAQ Cell&quot;) as! FAQsItemCell
          faqItem.answerLabel.isHidden = true
      }
  }
  </code></pre>