我有一个带有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"];
}
尝试实施
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
。
写作cellForItemAtIndexPath:indexPath
中didSelectItemAtIndexPath
会给你确切的项目被选中
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句