【问题标题】:didSelectItemAtIndexPath: sometimes not calleddidSelectItemAtIndexPath:有时不调用
【发布时间】:2017-07-05 07:49:30
【问题描述】:

我的UICollectionView 有一个奇怪的行为。有时didSelectItemAtIndexPath: 没有被调用。但是,如果我选择另一个项目并且他们可以单击上一个项目。

  1. 代表们没事。
  2. 手势识别器被禁用
  3. UICollectionView 在前面。在此之前什么都没有

我的代码:

- (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");
}

我哪里错了?提前致谢

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

【问题讨论】:

  • 没有真正的代码是无法分辨的...
  • 如果你解决了请贴出答案

标签: objective-c uicollectionview didselectrowatindexpath


【解决方案1】:

确保调用正确的 CollectionView 委托

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

你可能正在打电话

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

【讨论】:

  • 感谢您的回复。正如我所说 - 代表没问题 :) 它调用正确,只是在随机时刻它不起作用:(
  • @ArtemZ。你在课堂上实施过某种单击手势吗?
  • 是的,我做到了,但它们已被禁用。我已经设置了断点——它们没有被调用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多