Manage Collection View height inside the Table View Cell using swift 4


Collection View height inside the Table View Cell

In Most of time we use the collection view inside the table view cell if the collection view flow is vertical then we need to increase the height of table view cell or if flow layout is horizontal then we fix some constant height for table view cell .

Here I am discussing about how to manage the table view cell height automatically if collection view flow layout is vertical

Follow the Steps:

1: Go to Table view Cell class & create the outlet of collection view & collection view Height Constraints.

2: Now Register the Collection view cell so we can use .

3: Now write their All delegate & data source method inside the table view cell class.



4: Now the Collection View delegate & data source are set , now move to Table View Delegate & Data source.

5: Now register the tableview cell

6: After register the Tableview Cell & we have to define their delegate & Data source.

7: Now its Time to return the cell , here i am creating the vertical flow of collection view where the collection view height is fixed, so its automatically increase the table view cell size.


8 Notes : these are the important part to automate your table view cell

cell.frame = tableView.bounds



cell.productCollectionViewHeight.constant = cell.prodcutCollectionView.collectionViewLayout.collectionViewContentSize.height

9: Now your Table View Cell automatically increase without calculating the height of each collection view.




. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • ilham
    any example code
    • kunal prasad (Moderator)
      Hi we have already given a example code.
  • iBrahim
    Hi, thanks for this helpful post. Just one problem that is when I scroll through my tableview
    the first cell resize and get to long like the same size of the cell underneath it
    • kunal prasad (Moderator)
      Hi ,
      Just replace the code where you reload the table view by this extension .


      extension UITableView {
      func reloadDataWithAutoSizingCellWorkAround() {


    • kunal prasad (Moderator)
      Do this work on main thread.
  • srikanth
    there is lag in table view while loading a new cell in table view
    lag occurred because of reloading collection view and adding collection view height
  • Muhammed Eviz
    do you have any github link for this example code because, I did not understand about “where I will write these codes” So, may i get a github link about this example project.
  • Petfect answer
  • css.php

    Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.

    Hussein Zawia

    Hussein Zawia

    Co-founder, 24Dokan

    Talk to Sales


    Live Chat
    Start a Project

      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home