title: How do I show a UITableView within a UICollectionViewCell
body: <p>I am a new Swift programmer and I am currently working on a <strong>very</strong> simple to-do-list application. The catch is that I want to display a not-to-do list as well. Additionally, I am attempting to do this all through code. </p>
  
  <p>I want the user to be able to scroll horizontally between 2 CollectionViewCells, that each have a TableView within them displaying a 'To Do List' and a 'Not To Do List'. </p>
  
  <p>So far I have a ViewController that creates a UICollectionView that has 2 custom cells that each fills up the window, so the user can scroll between them. </p>
  
  <p>I am working on the "Not To Do List" cell, and I am trying to display a TableView within it, but I am having difficulty displaying it.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
  ...
  collectionView.register(ToDoListCell.self, forCellWithReuseIdentifier: toDoListCellid)
  collectionView.register(NotToDoListCell.self, forCellWithReuseIdentifier: notToDoListCellid)
  ...
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      if (indexPath.item == 0) {
          let toDoCell = collectionView.dequeueReusableCell(withReuseIdentifier: toDoListCellid, for: indexPath)
          return toDoCell
      }
      else {
          let notToDoCell = collectionView.dequeueReusableCell(withReuseIdentifier: notToDoListCellid, for: indexPath)
          return notToDoCell
      }
  }
  
  
  
  class NotToDoListCell: UICollectionViewCell {
  
  var ntdlArray = ["Play Video Games", "Eat out", "Watch Netflix"]
  let ntdlCell = "ntdlCell"
  
  override init(frame: CGRect) {
      super.init(frame: frame)
      backgroundColor = UIColor.orange
  }
  
  required init?(coder aDecoder: NSCoder) {
      fatalError("init(coder:) has not been implemented")
  }
  }
  
  
  
  extension NotToDoListCell: UITableViewDelegate, UITableViewDataSource {
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return ntdlArray.count
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return 1
  }
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: ntdlCell, for: indexPath)
  
      cell.textLabel?.text = ntdlArray[indexPath.item]
  
      return cell
  }
  
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      return 50
  }
  }
  </code></pre>
  
  <p>I would expect that the table view would show up with 3 rows of text containing: "Play Video Games", "Eat Out", and "Watch Netflix" but all I see is an orange screen (from when I set the background color of the NotToDoListCell to orange). Any help would be greatly appreciated.</p>
  
  <p>Thank you in advance. </p>