【问题标题】:UICollectionView didselect doesn't workUICollectionView didselect 不起作用
【发布时间】:2013-06-13 20:50:42
【问题描述】:

每次我按下一个单元格时,我都希望该单元格改变图像:

- (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。

【问题讨论】:

    标签: iphone ios uicollectionview reloaddata didselectrowatindexpath


    【解决方案1】:

    您已实现didDeselectItemAtIndexPath 而不是didSelectItemAtIndexPath,因此当您选择其他单元格时,您首先选择的单元格将被取消选择并触发didDeselectItemAtIndexPath

    【讨论】:

      【解决方案2】:

      使用了错误的方法。它是didSelectItemAtIndexpath 用于定义目的而不是didDeselect

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-22
        • 2018-03-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多