【问题标题】:How to change image in a collection view cell如何更改集合视图单元格中的图像
【发布时间】:2014-08-23 07:21:10
【问题描述】:

我有一个带有 imageview 的 CollectionView 单元格。问题是我想在选择单元格时更改单元格的图像。有人可以帮帮我吗?

我尝试了以下方法。但它不起作用。

- (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"];
}

【问题讨论】:

  • 什么是cell.MarkImg??
  • 它只是一个 UIImageView。
  • 好的,所以你在故事板中设计了那个图像视图?
  • 您是否检查了图像名称是否正确以及扩展名?
  • 图片扩展名和名称正确。

标签: ios uiimageview uicollectionviewcell


【解决方案1】:

尝试实施

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"]; 

didSelectItemAtIndexPath.

didSelectItemAtIndexPath 中写入cellForItemAtIndexPath:indexPath 将为您提供要选择的确切项目

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-06
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多