Ios 在UICollectionView中显示图像
我使用UICollectionview和自定义单元格 因此,我创建了一个包含图像名称的NSArray,当我尝试放入自定义单元格时,却什么也没有出现,我不明白为什么会发生这种情况 在viewDidLoad中Ios 在UICollectionView中显示图像,ios,uicollectionview,Ios,Uicollectionview,我使用UICollectionview和自定义单元格 因此,我创建了一个包含图像名称的NSArray,当我尝试放入自定义单元格时,却什么也没有出现,我不明白为什么会发生这种情况 在viewDidLoad中 [super viewDidLoad]; albums = [[NSArray alloc] initWithObjects:@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png",@"noImage.png",@"noI
[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];
这里是显示我的单元格的my 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 ImageName:[albums objectAtIndex:indexath.row]];cell.picture.image=[UIImage ImageName:[albums objectAtIndex:indexath.row]];“
thx您所拥有的应该可以使用(虽然不需要注册类,但只有nib可以)。您是否将控制器作为集合视图的委托和数据源?你把IB的collectionView插座接上了吗?你看到背景图像了吗?backgroundView中是否显示了thumbnail.png?我看到了显示的单元格,但无法查看数组中的图像