Iphone UICollectionView未选择';行不通
每次按下单元格时,我都希望该单元格更改图像:Iphone UICollectionView未选择';行不通,iphone,ios,uicollectionview,reloaddata,didselectrowatindexpath,Iphone,Ios,Uicollectionview,Reloaddata,Didselectrowatindexpath,每次按下单元格时,我都希望该单元格更改图像: - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { if ([[arrayOfImages objectAtIndex:indexPath.item] isEqual: @"dog.png"]) { [arrayOfImages replace
- (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一样。您已经实现了
didDecelectItemAtIndexPath
而不是didSelectItemAtIndexPath
,因此,当您选择另一个单元格时,您首先选择的单元格将被取消选择,并触发所使用的DIDDelectItemAtIndexPath
错误方法。定义DIDDelectItemAtIndexPath的目的不是DIDDelecte