您的位置:首页 > 其它

collectionView的注意事项

2016-01-07 15:30 302 查看
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"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: