0

我使用 UICollectionview 和自定义单元格。

因此,我创建了一个带有图像名称的 NSArray,当我尝试放入我的自定义单元格但没有出现任何内容时,我不明白它为什么会发生。

在 viewDidLoad

 [super viewDidLoad];



albums = [[NSArray alloc] initWithObjects:@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png", nil];


[self.collectionView registerClass:[CVCell class] forCellWithReuseIdentifier:@"cvCell"];

UINib *cellNib = [UINib nibWithNibName:@"CVCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cvCell"];

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(150, 150)];

//[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.collectionView setCollectionViewLayout:flowLayout];

这里显示我的单元格的 cellForItemAtIndexPath 方法

-(CVCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {


static NSString *cellIdentifier = @"cvCell";

CVCell *cell = (CVCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"thumbnail.png"]];

cell.picture.image = [UIImage imageNamed:[albums objectAtIndex:indexPath.row]];
return cell;

}

而且我觉得这个动作不起作用或者当我伤害到东西时“ cell.picture.image = [UIImage imageNamed:[albums objectAtIndex:indexPath.row]];cell.picture.image = [UIImage imageNamed:[albums objectAtIndex:indexPath .row]]; "

谢谢

4

0 回答 0