0

I have a UICollectionView and a custom UIcollectionViewCell.
Inside that cell there is one UITableView.

The content of the tableview changes dynamically so it's height also changes dynamically.
I want UICollectionViewCell to change it's height with respect to the tableview inside the Collectionviewcell.

How to do that?

D4ttatraya
  • 3,344
  • 1
  • 28
  • 50
Sajib Ghosh
  • 410
  • 1
  • 6
  • 17
  • Possible duplicate of [Dynamic size UICollectionView cell](http://stackoverflow.com/questions/23760275/dynamic-size-uicollectionview-cell) – 7vikram7 Jul 26 '16 at 07:44

1 Answers1

1

Use collectionView's delegate for setting size to cell,

Objective-C

- (CGSize)collectionView:(UICollectionView *)collectionView
              layout:(UICollectionViewLayout*)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath {

      NSLog(@"SETTING SIZE FOR ITEM AT INDEX %d", indexPath.row);

      //Calculate the height required for tableView inside the cell and set it to the cell
      return CGSizeMake(80, 80);
}

Swift

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

      NSLog(@"SETTING SIZE FOR ITEM AT INDEX %d", indexPath.row);

      //Calculate the height required for tableView inside the cell and set it to the cell
      return CGSizeMake(80, 80);
}

Hope it helps you.

Bharat Modi
  • 4,158
  • 2
  • 16
  • 27