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"];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章