title: UITableView in UICollectionView
body: <p>I placed a <code>tableView</code> inside a <code>collectionView</code> and added the delegates. The problem is, that I want to control the data in the different <code>tableViews</code> in the <code>collectionView</code>.</p>
  
  <p>Every <code>collectionView</code> holds a label with the name of the current day (e.g.: "Monday"). Below the label is a <code>tableView</code>. In the <code>tableView</code> should be displayed different data, based on the index of the <code>collectionView</code>.</p>
  
  <p>In my example, every <code>tableView</code> has two cells. The <code>tableView</code> in the first item of the <code>collectionView</code> should display: <code>cell1: "1"</code> and <code>cell2: "2"</code>, the <code>tableView</code> in the second item should display: <code>cell1: "3"</code> and <code>cell2: "4"</code>.</p>
  
  <p><strong>I'm currently using the code below:</strong></p>
  
  <pre><code>    import UIKit
  
  class StundenplanCollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UITableViewDataSource, UITableViewDelegate {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          myHours.append(myH0)
          myHours.append(myH1)
          myHours.append(myH2)
          myHours.append(myH3)
          myHours.append(myH4)
          myHours.append(myH5)
  
          collectionView.delegate = self
          collectionView.dataSource = self
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      //MARK: Outlets
      @IBOutlet weak var collectionView: UICollectionView!
  
      //MARK: Variables
      var myDays = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag"]
      var myHours: [[String]] = Array() //Array that holds myH1 - myH5
      var myH0 = ["1", "2"]
      var myH1 = ["3", "4"]
      var myH2 = ["5", "6"]
      var myH3 = ["7", "8"]
      var myH4 = ["9", "10"]
      var myH5 = ["Error", "Error"]
  
      var tableLoop = 0
  
      var headerColor: UIColor = UIColor( red: CGFloat(255/255.0), green: CGFloat(140/255.0), blue: CGFloat(60/255.0), alpha: CGFloat(1.0))
  
  
      //MARK: Table and Collection View
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return myDays.count
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell: StundenplanCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "stundenplanCollectionCell", for: indexPath) as! StundenplanCollectionViewCell
          cell.titleLabel.text = myDays[indexPath.row]
          cell.titleLabel.backgroundColor = headerColor
          cell.titleLabel.textColor = UIColor.white
          return cell
      }
  
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return myHours[tableLoop].count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell: StundenplanTableViewCell = tableView.dequeueReusableCell(withIdentifier: "stundenplanTableCell", for: indexPath) as! StundenplanTableViewCell
          cell.titleLabel.text = myHours[/*Here should the indexPath.row of the collectionView item be placed*/][indexPath.row]
          return cell
      }
  }
  
  class StundenplanCollectionViewCell: UICollectionViewCell {
      @IBOutlet weak var titleLabel: UILabel!
      @IBOutlet weak var tableView: UITableView!
  }
  
  class StundenplanTableViewCell: UITableViewCell {
      @IBOutlet weak var titleLabel: UILabel!
  }
  </code></pre>
  
  <p><strong>Image 1:</strong> Here you can see the first <code>tableView</code> in the <code>collectionView</code> (first item of <code>collectionView</code>):</p>
  
  <p><img src="https://i.stack.imgur.com/ul2Hl.png" alt="image 1"></p>
  
  <p><strong>Image 2:</strong> Here you can see the second tableView in the collectionView (second Item of collectionView):</p>
  
  <p><img src="https://i.stack.imgur.com/Kjrs2.png" alt="image 2"></p>
  
  <p><strong>Image 3:</strong> Storyboard:</p>
  
  <p><img src="https://i.stack.imgur.com/QzpUu.png" alt="image 3"></p>
  
  <p><strong>Image 4:</strong> Structure of the different objects in the view:</p>
  
  <p><img src="https://i.stack.imgur.com/zoW4a.png" alt="image 4"></p>
  
  <p><strong>Updated code</strong> (according to the answer by @missionMan - Thanks by the way!):</p>
  
  <pre><code>import UIKit
  
  class StundenplanCollectionViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          navigationController?.navigationBar.prefersLargeTitles = false
          navigationController?.navigationBar.prefersLargeTitles = true
          navigationItem.largeTitleDisplayMode = .always
  
          myHours.append(myH0)
          myHours.append(myH1)
          myHours.append(myH2)
          myHours.append(myH3)
          myHours.append(myH4)
          myHours.append(myH5)
  
          collectionView.delegate = self
          collectionView.dataSource = self
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
  
      //MARK: Outlets
      @IBOutlet weak var collectionView: UICollectionView!
  
      //MARK: Variables
      var myDays = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag"]
      var myHours: [[String]] = Array() //Array that holds myH1 - myH5
      var myH0 = ["1", "2"]
      var myH1 = ["3", "4"]
      var myH2 = ["5", "6"]
      var myH3 = ["7", "8"]
      var myH4 = ["9", "10"]
      var myH5 = ["Error", "Error"]
  
      var headerColor: UIColor = UIColor( red: CGFloat(255/255.0), green: CGFloat(140/255.0), blue: CGFloat(60/255.0), alpha: CGFloat(1.0))
  
  
      //MARK: Table and Collection View
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return myDays.count
      }
  
      public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          guard let cell = tableView.dequeueReusableCell(withIdentifier: "stundenplanCollectionViewCell") as? StundenplanCollectionViewCell else { //how can I access the inner tableView? Error: Use of unresolved identifier 'tableView'
              return UICollectionViewCell()
          }
  
          //set data and reload inner table from outer view controller (StundenplanCollectionViewController according to your code)
          cell.dayItems = myHours[indexPath.row]
          cell.tableView.reloadData()
          //...
  
          return cell
      }
  
  
  class StundenplanCollectionViewCell: UICollectionViewCell {
      @IBOutlet weak var titleLabel: UILabel!
      @IBOutlet weak var tableView: UITableView!
      var dayItems: [String] = []
  
      override func awakeFromNib() {
          super.awakeFromNib()
          self.tableView.delegate = self    // &lt;-- set delegates inner table
          self.tableView.dataSource = self
      }
  }
  
  extension StundenplanCollectionViewCell: UITableViewDataSource, UITableViewDelegate {
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return dayItems.count
      }
  
      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return 100
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell: StundenplanTableViewCell = (tableView.dequeueReusableCell(withIdentifier: "stundenplanTableViewCell") as? StundenplanTableViewCell)!
          //...
          return cell
      }
  }
  
  class StundenplanTableViewCell: UITableViewCell {
      @IBOutlet weak var titleLabel: UILabel!
  }
  </code></pre>