UICollectionView:
-(id)initWithCoder:(NSCoder *)aDecoder{
if(self =[super initWithCoder:aDecoder]){
return [self init];
}
return self;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.products.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
LJProductCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.productItem=self.products[indexPath.row];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
LJProductBaseViewController *productDetailVC=[[LJProductBaseViewController alloc]init];
[self.navigationController pushViewController:productDetailVC animated:YES];
}
- (UICollectionViewFlowLayout *) flowLayout{
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.headerReferenceSize = CGSizeMake(300.0f, 50.0f); //设置head大小
return flowLayout;
}
本文介绍如何使用UICollectionView来展示商品列表,包括初始化CollectionView、配置布局、加载数据到单元格及处理商品点击事件等关键步骤。
749

被折叠的 条评论
为什么被折叠?



