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