7

我有一個UITableview。其中一個UITableViewCell'sUICollectionview,實例名稱爲「amenityView」。如下所示,UICollectionViewDelegateUICollectionViewDataSource設置在storyboard中。以下方法被調用並且數據按預期填充。collectionView:didSelectItemAtIndexPath:沒有被調用

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collection cellForItemAtIndexPath:(NSIndexPath *)indexPath 

enter image description here

但是,下面的方法並沒有被調用時,我選擇包含在UICollectionViewUICollectionViewCell。我錯過了什麼?

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

UPDATE: 返回YES在該方法中collectionView:shouldSelectItemAtIndexPath:將調用下面兩種方法。至少這是我的缺失。希望這將有助於一些機構... enter image description here

+1

是[「'.allowsSelection'」](https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionView_class/Reference/Reference.html#//apple_ref/occ/instp/UICollectionView/allowedSelection)爲你的收藏視圖設置爲YES? –

+0

@MichaelDautermann。感謝您的答覆。 「.allowsSelection」設置爲「YES」。 – Loozie

+0

它所坐的表格視圖單元格是否允許用戶交互或選擇單元格本身? –

回答

1

是否調用表視圖的didSelectRowAtIndexPath?如果是這樣,表格視圖可能會攔截觸摸並且不會將它們傳遞給內部的集合視圖。我從來沒有做過你想要做的解決方案,但集合視圖位於滾動視圖內,並且以一種合理的方式將觸摸信息傳遞到集合視圖可能並不容易,因此您可能需要禁用點擊表格視圖單元格以便集合視圖響應觸摸。

相關問題