collectionView的注意事项

1:有headerView 和 footerView

做法:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

{

    UICollectionReusableView *reusableView = nil;


    if (kind == UICollectionElementKindSectionHeader) {

        if (indexPath.section == 2) {

            YQHomeJieDuanCollectionReusableView *reviewHeader = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"YQHomeJieDuanCollectionReusableView" forIndexPath:indexPath];

            reusableView = reviewHeader;

        }

    }

    if (kind == UICollectionElementKindSectionFooter) {

        YQSectionCollectionReusableView *reViewFooter = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"YQSectionCollectionReusableView" forIndexPath:indexPath];

        reusableView = reViewFooter;

    }

    

    return reusableView;

}


2:cell用xib的话别忘了注册。
做法:

  UINib *nib = [UINib nibWithNibName:@"YQHomeFeedBigImageCollectionViewCell" bundle:nil];

    [self.baseCollectionView registerNib:nib forCellWithReuseIdentifier:@"YQHomeFeedBigImageCollectionViewCell"];

3:xib 做成的headerView或者footerView 要手动将xib 的引用类改为自己建的类名。要不然会崩溃


4:注册headerView或者footerView

做法:

    UINib *nib5 = [UINib nibWithNibName:@"YQHomeJieDuanCollectionReusableView" bundle:nil];

    [self.baseCollectionView registerNib:nib5 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"YQHomeJieDuanCollectionReusableView"];

    

    UINib *nib6 = [UINib nibWithNibName:@"YQSectionCollectionReusableView" bundle:nil];

    [self.baseCollectionView registerNib:nib6 forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"YQSectionCollectionReusableView"];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值