如何重用自定义UICollectionView?

时间:2014-01-04 11:37:44

标签: ios iphone uicollectionviewcell

我使用了以下代码

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.itemSize = CGSizeMake(78, 86);
[layout setMinimumInteritemSpacing:4.5f];
[layout setMinimumLineSpacing:4.5f];
self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 320, 100) collectionViewLayout:layout];
 [self.collectionView setDataSource:self];
[self.collectionView setDelegate:self];
[self.collectionView setTag:1];
[self.collectionView setBackgroundColor:[UIColor clearColor]];

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 

如何在UICollectionViewCell中重用单元标识符。

1 个答案:

答案 0 :(得分:1)

试试这个

static NSString *kCellReuseIdentifier = @"cell"; 

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellReuseIdentifier forIndexPath:indexPath];