title: CollectionView Inside TableView
body: <p>I have a <code>CollectionView</code> in <code>TableViewController</code> cell the <code>tableView</code>contains 3 sections each section is a different category. How I can pass different data in each section. Like Netflix app</p>
  
  <p><strong>In UICollectionViewController file</strong></p>
  
  <pre class="lang-swift prettyprint-override"><code>import UIKit
  import Alamofire
  
  class HomeViewController: UITableViewController, MovieDataDelegate {
  
      let tableViewHeaderIdentifier = "FeaturedTableHeader"
      var homePresenter : HomePresenter!
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view.
  
          let headerNib = UINib(nibName: "FeaturedUITableViewHeaderView", bundle: nil)
          tableView.register(headerNib, forHeaderFooterViewReuseIdentifier: tableViewHeaderIdentifier)
  
          homePresenter = HomePresenter()
          homePresenter.delegate = self
          homePresenter.fetchData()
          homePresenter.fetchImageData()
  
      }
  
  
      func arrayOfMoviesNames(names: [String]) {
          //print(homePresenter.homeData.moviesNamesArray)
          tableView.reloadData()
      }
  
      func arrayOfPosters(path: [String]) {
          //print(homePresenter.homeData.posterPathsArray)
      }
  
  
  
      //MARK: - Home UI table
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return 1
      }
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell =  tableView.dequeueReusableCell(withIdentifier: "featuredCell", for: indexPath) as! FeaturedTableViewCell
  
          cell.homeCollectionView.dataSource = self
          return cell
      }
  
      override func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 3
      }
  
      override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
          let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: tableViewHeaderIdentifier) as! FeaturedUITableViewHeaderView
  
          switch section {
          case 0:
              headerView.isHidden = true
          case 1:
              headerView.catagoryLabel.text = "Popular Movies"
          case 2:
              headerView.catagoryLabel.text = "Celebs"
          default:
              headerView.catagoryLabel.text = "" as String
          }
  
          return headerView
      }
  
      override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
  
          if section == 0 {
              return 0
          }
          return 35
      }
  
      override func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -&gt; CGFloat {
          return 12
      }
  
      override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  
          guard let tableViewCell = cell as? FeaturedTableViewCell else { return }
  
          tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
  
      }
  
  
  }
  
  
  
  
  //MARK: - collectionView
  extension HomeViewController : UICollectionViewDataSource, UICollectionViewDelegate {
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return homePresenter.homeData.moviesNamesArray.count
      }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "homeCollectionCell", for: indexPath) as! HomeCollectionViewCell
          cell.posterImage.image = UIImage(named: "Aladdin")
  
          cell.movieName.text = "coco"
  
          return cell
      }
  
  
  }
  
  </code></pre>
  
  <p><strong>In UITableViewCell file</strong></p>
  
  <pre class="lang-swift prettyprint-override"><code>import UIKit
  
  class FeaturedTableViewCell: UITableViewCell {
  
      @IBOutlet weak var homeCollectionView: UICollectionView!
  
  
      override func awakeFromNib() {
          super.awakeFromNib()
          // Initialization code
          let collectionNib = UINib(nibName: "HomeCollectionViewCell", bundle: nil)
          homeCollectionView.register(collectionNib, forCellWithReuseIdentifier: "homeCollectionCell")
      }
  
      override func setSelected(_ selected: Bool, animated: Bool) {
          super.setSelected(selected, animated: animated)
  
          // Configure the view for the selected state
      }
  
  }
  extension FeaturedTableViewCell {
  
       func setCollectionViewDataSourceDelegate&lt;D: UICollectionViewDataSource &amp; UICollectionViewDelegate&gt;(_ dataSourceDelegate: D, forRow row: Int) {
  
            homeCollectionView.delegate = dataSourceDelegate
            homeCollectionView.dataSource = dataSourceDelegate
            homeCollectionView.tag = row
            homeCollectionView.reloadData()
  }
  
  }
  
  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/hKq4p.jpg" rel="nofollow noreferrer">screenshot of app</a></p>
  
  <p>I want to show diffrent image and text for each section of tabelview</p>