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