title: CellForRowAt not called when adding TableView Programmatically
body: <p>I'm creating a UI (programmatically) that will show two main parts <br/></p>
  <ul>
  <li><p>The first part will show a video Player</p>
  </li>
  <li><p>The second part will show a UITableView with more videos</p>
  </li>
  </ul>
  <p>I have successfully worked on the first part, it's working and it's occupying a small portion of the screen at the top</p>
  <p>Using the same logic I tried to add a UITableView in the main Container View, but all I can see is an empty tableView</p>
  <p>I also tried to log messages when cellForRowAt will be called, but nothing is printed , I concluded that the cellForRowAt is not being called</p>
  <p>Here's the code of the class that does all of this :</p>
  <pre><code>import UIKit
  import AVFoundation
  
  
  class VideoLauncher: NSObject , UITableViewDataSource, UITableViewDelegate{
  
  
  let data : [String] =  [&quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;]
  
  // TableView initialization
  let tableView : UITableView = {
      let t  = UITableView()
      t.translatesAutoresizingMaskIntoConstraints = false
      t.register(UITableViewCell.self, forCellReuseIdentifier: &quot;customCell&quot;)
      t.rowHeight = 80
  
      return t
  }()
  
  
  func showVideoPlayer(){
      
      if let keyWindow = UIApplication.shared.keyWindow {
        
          // View Container that will contain the player and the tableview
          let mainContainer = UIView(frame: keyWindow.frame)
          mainContainer.backgroundColor = .white
          mainContainer.frame = CGRect(x: keyWindow.frame.width - 30, y: keyWindow.frame.height - 30, width: 10, height: 10)
        
          // Creating and adding the first part : PlayerView
          let height = keyWindow.frame.width * 9 / 16
          let videoPlayerFrame = CGRect(x: 0, y: 0, width: keyWindow.frame.width, height: height)
          let videoPlayerView = VideoPlayerView(frame: videoPlayerFrame)
          mainContainer.addSubview(videoPlayerView)
          
          
          // Creating and adding the second Part: TableView
          // I'm adding the tableView to another UIView : tableViewContainer
         
          let tableViewContainer = UIView()
             tableViewContainer.frame = CGRect(x: 0, y: videoPlayerView.frame.maxY, width: keyWindow.frame.width, height: keyWindow.frame.height)
       
          mainContainer.addSubview(tableViewContainer)
          
          tableView.delegate = self
          tableView.dataSource = self
          tableView.frame  = CGRect(x: 0, y: 0, width: tableViewContainer.frame.width, height: tableViewContainer.frame.height)
          
          tableViewContainer.addSubview(tableView)
  
          keyWindow.addSubview(mainContainer)
            
          UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut) {
              mainContainer.frame = CGRect(x: keyWindow.frame.minX, y: keyWindow.frame.minY + 35, width: keyWindow.frame.width, height: keyWindow.frame.height)
          } completion: { (Bool) in
            
          }
      
      }
  }
  
  // MARK: - TABLEVIEW DATA SOURCE
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      print(&quot;NumberOfRows In Section&quot;)
      return data.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      print(&quot;Cell For row At&quot;)
      let cell = tableView.dequeueReusableCell(withIdentifier: &quot;customCell&quot;, for: indexPath)
      let s = data[indexPath.row]
      cell.textLabel?.text = s
      return cell
  }
  }
  </code></pre>
  <p>And all I get as output is this :</p>
  <p><a href="https://i.stack.imgur.com/zlk71.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zlk71.png" alt="enter image description here" /></a></p>
  <p><b>----- EDIT ------ </b><br/>
  Based on different suggestions that I received in the comment section , I modified my code a little bit, I anchored the tableView to its container and called tableView.reloadData() When the animation is completed.</p>
  <p>As a result, CellForRowAt is called once, and cells are shown but disappear as quickly as they appear.</p>
  <p>Below is the modified version of my previous code</p>
  <pre><code>class VideoLauncher: NSObject , UITableViewDataSource{
    
      
      let data : [String] =  [&quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;, &quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;, &quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;, &quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;, &quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;, &quot;String 1&quot;, &quot;String 2&quot;, &quot;String 3&quot;, &quot;String 4&quot;, &quot;String 4&quot;]
      
      // TableView initialization
      let tableView : UITableView = {
          let t  = UITableView()
          t.register(UITableViewCell.self, forCellReuseIdentifier: &quot;customCell&quot;)
          return t
      }()
      
  
      func showVideoPlayer(){
          
          self.tableView.dataSource = self
          if let keyWindow = UIApplication.shared.keyWindow {
            
              // View Container that will contain the player and the tableview
              let mainContainer = UIView(frame: keyWindow.frame)
              mainContainer.backgroundColor = .white
              mainContainer.frame = CGRect(x: keyWindow.frame.width - 30, y: keyWindow.frame.height - 30, width: 10, height: 10)
              
          
              // Creating and adding the first part : PlayerView
              let height = keyWindow.frame.width * 9 / 16
              let videoPlayerFrame = CGRect(x: 0, y: 0, width: keyWindow.frame.width, height: height)
              let videoPlayerView = VideoPlayerView(frame: videoPlayerFrame)
              mainContainer.addSubview(videoPlayerView)
              
          
              // Creating and adding the second Part: TableView
              // I'm adding the tableView to another UIView : customView
              let tableViewContainer = UIView()
              tableViewContainer.translatesAutoresizingMaskIntoConstraints = false
                
              mainContainer.addSubview(tableViewContainer)
              tableViewContainer.topAnchor.constraint(equalTo: videoPlayerView.bottomAnchor).isActive = true
              tableViewContainer.bottomAnchor.constraint(equalTo: mainContainer.bottomAnchor).isActive = true
              tableViewContainer.leftAnchor.constraint(equalTo: mainContainer.leftAnchor).isActive = true
              tableViewContainer.rightAnchor.constraint(equalTo: mainContainer.rightAnchor).isActive = true
              
              tableViewContainer.addSubview(self.tableView)
              self.tableView.translatesAutoresizingMaskIntoConstraints = false
              self.tableView.topAnchor.constraint(equalTo: tableViewContainer.topAnchor).isActive = true
              self.tableView.bottomAnchor.constraint(equalTo: tableViewContainer.bottomAnchor).isActive = true
              self.tableView.leftAnchor.constraint(equalTo: tableViewContainer.leftAnchor).isActive = true
              self.tableView.rightAnchor.constraint(equalTo: tableViewContainer.rightAnchor).isActive = true
             
              keyWindow.addSubview(mainContainer)
              
              UIView.animate(
                  withDuration: 0.5,
                  delay: 0,
                  usingSpringWithDamping: 1,
                  initialSpringVelocity: 1,
                  options: .curveEaseOut) {
  
                  mainContainer.frame = CGRect(x: keyWindow.frame.minX, y: keyWindow.frame.minY + 35, width: keyWindow.frame.width, height: keyWindow.frame.height)
  
                  } completion: { (Bool) in
  
                      self.tableView.reloadData()
              }
          }
      }
      // MARK: - TABLEVIEW DATA SOURCE
      
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          print(&quot;NumberOfRows In Section&quot;)
          return data.count
      }
      
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          print(&quot;Cell For row At&quot;)
          let cell = tableView.dequeueReusableCell(withIdentifier: &quot;customCell&quot;, for: indexPath)
          let s = data[indexPath.row]
          cell.textLabel?.text = s
          return cell
      }
   }
  </code></pre>
  <p>And what I really get as output is this</p>
  <p><a href="https://i.stack.imgur.com/XXv1r.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XXv1r.gif" alt="enter image description here" /></a></p>
  <p>What could be the cause of the behaviour of the TableView  ?</p>