2017-07-05 52 views
1

我有一個奇怪的行爲,我的UICollectionView。有時didSelectItemAtIndexPath:未被調用。但是,如果我選擇另一個項目,他們可以點擊上一個項目。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"); 
} 

哪裏可能是錯誤的?在此先感謝

手勢識別器現在被禁用。我已經設置斷點,他們沒有僱用

+0

這是不可能告訴沒有任何真正的代碼。 .. – Alladinian

回答

0

請確保調用適當的CollectionView委託

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

會提醒

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

感謝您的回覆。正如我所說 - 代表是正確的:)它調用正確,只有在隨機時刻它不起作用:( –

+0

@ArtemZ。你有沒有在你的課堂上實施某種單擊手勢? –

+0

發佈你的代碼。 –

相關問題