Ios 如何更改集合视图单元格中的图像
我有一个带有imageview的CollectionView单元格。问题是我想在选中单元格时更改单元格的图像。有人能帮我吗 我尝试了以下方法,但不起作用Ios 如何更改集合视图单元格中的图像,ios,uiimageview,uicollectionviewcell,Ios,Uiimageview,Uicollectionviewcell,我有一个带有imageview的CollectionView单元格。问题是我想在选中单元格时更改单元格的图像。有人能帮我吗 我尝试了以下方法,但不起作用 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier=@"myCell"; GallaryCell *cell
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier=@"myCell";
GallaryCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.MarkImg.image=[UIImage imageNamed:@"mark.jpg"];
}
尝试实施
GallaryCell *cell= (GallaryCell *)[collectionView cellForItemAtIndexPath:indexPath];
cell.MarkImg.image=[UIImage imageNamed:@"mark.jpg"];
而不是
GallaryCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.MarkImg.image=[UIImage imageNamed:@"mark.jpg"];
在中选择ItemAtIndexPath
在
didSelectItemAtIndexPath
中写入cellForItemAtIndexPath:indexPath
将为您提供要选择的确切项目什么是单元格。标记??它只是一个UIImageView。确定了吗,您在故事板中设计了该imageview?您是否检查了图像名称是否正确以及扩展名?图像扩展名和名称是否正确。