Ios UICollectionView使用不同高度的单元格

Ios UICollectionView使用不同高度的单元格,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,所以我有一个集合视图控制器,它有3个单元格,因为每个单元格都有不同的布局。我的图片显示: 它们都有不同的单元格标识符,因此在我的cellForItemAtIndexPath函数中,我可以创建特定的单元格,如: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCel

所以我有一个集合视图控制器,它有3个单元格,因为每个单元格都有不同的布局。我的图片显示:

它们都有不同的单元格标识符,因此在我的cellForItemAtIndexPath函数中,我可以创建特定的单元格,如:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell;


    if(indexPath.row == 0)
    {
        static NSString *identifier = @"Cell1";
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier     forIndexPath:indexPath];
        [cell setNeedsLayout];
    }
    else if(indexPath.row == 1)
    {
        static NSString *identifier = @"Cell2";
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        [cell setNeedsLayout];
    }
    else
    {
        static NSString *identifier = @"Cell3";
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
        [cell setNeedsLayout];
    }

    return cell;
}
但当我模拟它时,所有的细胞都是相同大小的:

有没有办法强制单元格达到我定义的大小,或者有没有更合适的方法

或者使用以下方法:

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

如果只有3个单元格,为什么要在此处使用集合视图?使用常规子视图更容易做到这一点。