title: TableView won't populate
body: <p>I've added a UITableView control to a UIAlertController to create a custom list picker. Everything worked fine until I tried to move all of my code into a new ListPicker class. Originally I had this code in the main viewcontroller and called <code>self.present</code> at the end of the <code>showListPicker</code> method. Everything worked fine then and my list populated properly with my items. But after moving to a separate class, I needed to reference the calling ViewController in my method call so I could present the alert over the calling ViewController. After doing this, everything works except my table view will not show any rows. The <code>numberOfRowsInSection</code> returns the correct number of rows but the <code>cellForRowAt</code> is never invoked.</p>
  <p>I've read some other posts that mentioned constraints being an issue. Something like the constraints were preventing the rows from being visible and therefore never having their data methods invoked. They were using interface builder though and the solution was to accept the constraint fixes.</p>
  <p>Can anybody see what I'm doing wrong here?</p>
  <p>I appreciate the help.</p>
  <p>Thanks,
  Joel</p>
  <p><a href="https://i.stack.imgur.com/NqBy5.png" rel="nofollow noreferrer">Empty TableView Snapshot</a></p>
  <pre><code>class ListPicker: UIViewController, UITableViewDelegate, UITableViewDataSource {
     
  //MARK: Variables
  
      var items: [String]?
    
  //MARK: ViewController Events
  
      override func viewDidLoad() {
          super.viewDidLoad()
          
      }
  
  //MARK: TableView Events
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return items?.count ?? 0
      }
      
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: &quot;cell&quot;)!
          
          cell.textLabel!.text = items![indexPath.row]
          
          return cell
      }
  
      func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }
  
  //MARK: Support Methods
  
      func showListPicker(
          viewController: UIViewController,
          title: String? = &quot;Select Item&quot;,
          message: String? = nil,
          items: [String]?,
          itemSelected: (@escaping (_ item: String) -&gt; ())
      ) {
          let alert = UIAlertController(
              title: title,
              message: &quot;\(message ?? &quot;&quot;)\n\n\n\n\n\n\n\n\n\n\n\n&quot;,
              preferredStyle: .alert
          )
          
          let rect = CGRect(
              x: 0,
              y: 0,
              width: 250,
              height: 250
          )
  
          let tableView = UITableView(frame: rect, style: .plain)
              tableView.register(UITableViewCell.self, forCellReuseIdentifier: &quot;cell&quot;)
              tableView.delegate = self
              tableView.dataSource = self
          
              tableView.rowHeight = 35
              tableView.backgroundColor = .white
              tableView.separatorInset.right = 15
              tableView.bounces = false
              tableView.layoutMargins = .init(top: 0, left: 0, bottom: 0, right: 0)
              tableView.layer.cornerRadius = 10
           
          alert.view.addSubview(tableView)
  
          tableView.topAnchor.constraint(equalTo: alert.view.subviews[0].topAnchor, constant: 90).isActive = true
          tableView.bottomAnchor.constraint(equalTo: alert.view.subviews[0].bottomAnchor, constant: -60).isActive = true
          tableView.leftAnchor.constraint(equalTo: alert.view.subviews[0].leftAnchor, constant: 10).isActive = true
          tableView.rightAnchor.constraint(equalTo: alert.view.subviews[0].rightAnchor, constant: 10).isActive = true
          
          let okAction = UIAlertAction(title: &quot;OK&quot;, style: .default, handler: {(alert: UIAlertAction!) in print(&quot;OK&quot;)})
          let cancelAction = UIAlertAction(title: &quot;Cancel&quot;, style: .cancel, handler: {(alert: UIAlertAction!) in print(&quot;cancel&quot;)})
  
          alert.addAction(okAction)
          alert.addAction(cancelAction)
  
          viewController.present(alert, animated: true) {
              if let row = tableView.indexPathForSelectedRow?.row {
                  self.dismiss(animated: true)
                  itemSelected(items![row])
              }
          }
      }
  </code></pre>
  <p>}</p>