实现功能是每次按下cell就会变换图片
- (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];
}
运行之后,点击一个cell,没有任何事情发生,但是如果点击其他cell,前一个cell就变换图片了。每次都是点击下一个cell上一个cell才开始变化图片。
是不是因为点击时collectionView没有更新?