每次我按下一个单元格时,我都希望该单元格更改图像:
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
if ([[arrayOfImages objectAtIndex:indexPath.item] isEqual: @"dog.png"]) {
[arrayOfImages replaceObjectAtIndex:indexPath.item withObject:@"cat.png"];
} else if ([[arrayOfImages objectAtIndex:indexPath.item] isEqual: @"cat.png"]) {
[arrayOfImages replaceObjectAtIndex:indexPath.item withObject:@"lion.png"];
} else if ([[arrayOfImages objectAtIndex:indexPath.item] isEqual: @"lion.png"]) {
[arrayOfImages replaceObjectAtIndex:indexPath.item withObject:@"dog.png"];
}
[myCollectionView reloadData];
}
我按下一个单元格,没有任何反应,现在如果我按下另一个单元格,前一个单元格会改变图像,并且我按下的每个单元格都会发生同样的事情。改变的图像始终是前一个单元格的图像。好像它没有更新collectionView,因为我再次按下collectionView。