关于UICollectionView的使用

1:今天有时间整理下自己这段时间开发IOS的总结

2:使用UICollectionView 的注意事项,

注意注册View 头部 

[self.collection registerNib:[UINib nibWithNibName:@"CKKHeaderTypeView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CKKHeaderTypeView"];

[self.collection registerNib:[UINib nibWithNibName:@"CKKNewHead" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CKKNewHead"];

[self.collection registerNib:[UINib nibWithNibName:@"CKKHomeNoDataView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"CKKHomeNoDataView"];

这些都是自定义的头部View

代理方法:处理头部View

                  下面是头部视图的代理方法:#pragma mark - 头部或者尾部视图- (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView viewForSupplementaryElementOfKind:(NSString*)kind atIndexPath:(NSIndexPath*)indexPath{//如果是头部视图 (因为这里的kind 有头部和尾部所以需要判断  默认是头部,严谨判断比较好)/*

JHHeaderReusableView 头部的类

kHeaderID  重用标识

*/if(kind ==UICollectionElementKindSectionHeader) {        JHHeaderReusableView *headerRV = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kHeaderID forIndexPath:indexPath];        headerRV.homeModel=self.bodyArray[indexPath.section];returnheaderRV;    }else//有兴趣的也可以添加尾部视图{returnnil;    }}


多少个Section

#pragma mark -- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

if ( section == 1 ) {

return self.hotCarSeriess.count;

}else if(section == 0 ){

return self.qyCarSeriess.count;

}else {

return 0;

}


}

多少组

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

if ([self.hotCarSeriess count] > 0) {

return 2;

}else {

return 3;

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容