didSelectItemAtIndexPath:有时不调用

时间:2017-07-05 07:49:30

标签: objective-c uicollectionview didselectrowatindexpath

我的UICollectionView有一种奇怪的行为。有时didSelectItemAtIndexPath:没有被调用。但是,如果我选择其他项目,我可以点击上一项。

  1. 代表们还可以。
  2. 手势识别器已停用
  3. UICollectionView在前面。此前没有任何内容
  4. 我的代码:

    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
        if (self.activeCollectionViewObjects.count > section) {
                NSArray *array = self.activeCollectionViewObjects[section];
                return array.count;
            }
        }
    }
    
    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        VenueLayoutCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kVenueLayoutCellReuseIdentifier forIndexPath:indexPath];
        self.activeCollectionViewCellsDictionary[indexPath] = cell;
        if (self.activeCollectionViewObjects.count > indexPath.section) {
            NSArray *rows = self.activeCollectionViewObjects[indexPath.section];
            if (rows.count > indexPath.row) {
                if ([rows[indexPath.row] isKindOfClass:[VenueLayoutCellObject class]]) {
                    VenueLayoutCellObject *object = rows[indexPath.row];
                    cell.cellObject = object;
    
                }
            }
        }
        [cell layoutIfNeeded];
        return cell;
    }
    
    
    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
    {
       NSLog(@"hello");
    }
    

    我哪里错了?提前致谢

    手势识别器现已停用。我设置了断点,他们不雇用

1 个答案:

答案 0 :(得分:2)

确保调用正确的CollectionView委托

- (void)collectionView:(UICollectionView *)collectionView     didSelectItemAtIndexPath:(NSIndexPath *)indexPath;

您可能正在致电

- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath;