Start a Project

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.layoutIfNeeded()

cell.prodcutCollectionView.reloadData()

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

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

 

 

 

Exit mobile version