Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UICollectionView未选择';行不通_Iphone_Ios_Uicollectionview_Reloaddata_Didselectrowatindexpath - Fatal编程技术网

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