Ios 在UICollectionView中的行中显示不同数量的单元格

Ios 在UICollectionView中的行中显示不同数量的单元格,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我希望有一个UICollectionView,第一行有一个单元格,具有行的所有宽度,第二行有3个单元格。 我已经研究了文档,但是我不能做。大概是这样的: 提前感谢在故事板的“集合”视图中制作2个单元原型,并将其设置为重用标识符 在ViewController的.m文件中实现此功能 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; }

我希望有一个
UICollectionView
,第一行有一个单元格,具有行的所有宽度,第二行有3个单元格。 我已经研究了文档,但是我不能做。大概是这样的:


提前感谢

在故事板的“集合”视图中制作2个单元原型,并将其设置为重用标识符

在ViewController的.m文件中实现此功能

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{        
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

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

    if (/*condition for small cell*/)// e.g.    indexPath.row % 3 != 0
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"smallCell" forIndexPath:indexPath];
    else
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bigCell" forIndexPath:indexPath];


    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (/*condition for small cell*/) // e.g.    indexPath.row % 3 != 0
        return CGSizeMake(65, 50);

    return CGSizeMake(318, 50);
}
完成此操作后,您将得到如下内容:


你确定你不只是想要一个部分标题吗?我想你应该尝试自定义布局。检查此链接我不想要标题,因为所有单元格都具有相同的重要性