title: How to reload tableView inside of a containerView?
body: <p>I have the following setup: BaseVC (container view inside)-connectedTo-commentsVC (inside of here is a tableView which will be filled with custom commentCells).</p>
  
  <p>Upon the baseVC loading this gets called:</p>
  
  <pre><code>  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  
      if let VC = segue.destination as? CommentsVC {
  
          VC.selectedMedia = selectedPost?.media[numberMedia]
          VC.commentCellDelegate = self
          VC.parentView = commentsContainer
          commentsVC1 = VC
          VC.post = selectedPost!
      }
  
  }
  </code></pre>
  
  <p>Then when a button is pressed in the BaseVC this gets called, bringing up the commentsVC with the tableView and then fetching the data that should go within it:</p>
  
  <pre><code>@objc func CommentsTapped(_ tap: UITapGestureRecognizer) {
      //Bring up the comments view and load all data into it.
      UIView.animate(withDuration: 0.2, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.9, options: .curveEaseOut, animations: {
          print(self.commentsVC1.commentCellDelegate!)
          self.commentsVC1.commentCellDelegate!.updateCommentSheet(frame: self.initalFrame.offsetBy(dx: 0, dy: 180))
          self.loadComments()
          //I tried calling self.commentsVC1.tableView.reloadData() here but nothing happens
      })
  }
  </code></pre>
  
  <p>Then at the bottom of the BaseVC class I have an extension which holds all the methods for the tableView:</p>
  
  <pre><code>extension Phase3VC: UITableViewDelegate, UITableViewDataSource {
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      if arrayOfComments.count == 0 {
          return 1
      } else {
          return arrayOfComments.count
      }
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = commentTableViewCell()
      do {
          print("jdkhfjkfhasjklfhds")
          let url = URL(string: (arrayOfComments[indexPath.row].user.profileImageUrlString)!)
          let imageData = try Data(contentsOf: url!)
          let image = UIImage(data: imageData)
  
          cell.dateOfComment.text = arrayOfComments[indexPath.row].date
          cell.commentText.text = arrayOfComments[indexPath.row].commentText
          cell.profImage.image = image
          cell.username.text = arrayOfComments[indexPath.row].user.username
      } catch {
  
  
            print(error, ": Failed in do block converting image")
          }
  
          return cell
      }
  
  }
  </code></pre>
  
  <p>So my question is <strong>how do I reload the tableView in order to get the data into the tableView?</strong> I have looked <a href="https://stackoverflow.com/questions/27604585/reload-tableview-inside-a-uiview">here</a> and <a href="https://stackoverflow.com/questions/43414625/updating-tableview-within-containerview">here</a> but neither helped. </p>
  
  <p><strong>I have attempted:</strong></p>
  
  <pre><code>func loadComments(completion: @escaping(()-&gt;())) {
  </code></pre>
  
  <p>and called at the end of firebase func like: <code>completion()</code> (do be aware it is .childAdded) </p>
  
  <p>and then do:            </p>
  
  <pre><code>self.loadComments {
                  self.commentsVC1.tableView.reloadData()
              }
  </code></pre>
  
  <p>But it did not work</p>
  
  <h2><strong>Update:</strong></h2>
  
  <p>Here is the fetching function:</p>
  
  <pre><code>    func loadComments(completion: @escaping(()-&gt;())) {
      print("Fetch comments")
  
      let ref = Database.database().reference()
      self.arrayOfComments.removeAll()
      ref.child("Comments").child(selectedPost!.user.userID!).child(selectedPost!.media[0].postID!).child("\(numberImage+1)").observe(.childAdded) { (snap) in
          let commentID = snap.key
          let uid = snap.childSnapshot(forPath: "UID").value as! String
          ref.child("users2").child(uid).observe(.value, with: { (snapshot) in
              let username = snapshot.childSnapshot(forPath: "username").value
              let profileImage = snapshot.childSnapshot(forPath: "profileImage").value
  
              let newUser = User(theuserID: uid, theUsername: username as! String, theprofImage: profileImage as! String)
  
              let commentText = snap.childSnapshot(forPath: "Comment").value!
              let timeStamp = snap.childSnapshot(forPath: "timeStamp").value!
              print(timeStamp, "This is the timeStamp")
              let date = ConvertDate(mediaTimestamp: timeStamp as! Double, isItForP3: false).getDate!
  
              let newComment = Comments(newUser: newUser, text: commentText as! String, timeStamp: date, NcommentID: commentID)
              self.arrayOfComments.append(newComment)
              print(self.arrayOfComments.count, ": comments added")
              self.commentsVC1.tableView.reloadData()
  
              completion()
          })
      }
  }
  </code></pre>