简体   繁体   English

如何动态更改UICollectionview单元格高度?

[英]How to change UICollectionview Cell Height dynamically?

I have a UICollectionView and a custom UIcollectionViewCell . 我有一个UICollectionView和一个自定义UIcollectionViewCell
Inside that cell there is one UITableView . 在该单元格内有一个UITableView

The content of the tableview changes dynamically so it's height also changes dynamically. tableview的内容会动态更改,因此其高度也会动态更改。
I want UICollectionViewCell to change it's height with respect to the tableview inside the Collectionviewcell. 我希望UICollectionViewCell相对于Collectionviewcell内的tableview更改其高度。

How to do that? 怎么做?

Use collectionView's delegate for setting size to cell, 使用collectionView的委托将大小设置为单元格,

Objective-C 目标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. 希望对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM