将nib加载到UICollectionViewCell中

时间:2013-02-17 21:34:25

标签: uicollectionview uicollectionviewcell

我刚开始使用UICollectionView所以请耐心等待我!

如何将笔尖装入细胞?

似乎我必须注册要使用的nib和类,但这不起作用。

代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    [collectionView registerClass:[CluelessSymbolCell class] forCellWithReuseIdentifier:@"Symbol cell"];
    [collectionView registerNib:[UINib nibWithNibName:@"CluelessSymbolCell" bundle:[NSBundle mainBundle]]  forCellWithReuseIdentifier:@"Symbol cell"];

    CluelessSymbolCell *cell = (CluelessSymbolCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Symbol cell" forIndexPath:indexPath];

    CluelessClue *clue = [clueManager clueForIndexPath:indexPath];

    [cell.backgroundImageView setImage:[UIImage imageNamed:[clue.imageNames objectAtIndex:0]]];

    return cell;
}

1 个答案:

答案 0 :(得分:1)

事实证明我的nib文件中有默认的视图控制器(隐藏了)以及我的自定义单元格 - doh!