在UICollectionView中显示图像

时间:2013-06-05 21:32:47

标签: ios uicollectionview

我使用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]];

THX

0 个答案:

没有答案