collectionView: didSelectItemAtIndexPath: does not get called
Asked Answered
W

1

7

I have a UITableview. One of the UITableViewCell's is a UICollectionview with instance name "amenityView". The UICollectionViewDelegate and the UICollectionViewDataSource are set in the storyboard as shown below. The following methods get called and the data is populated as expected.

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

enter image description here

However, the methods below didn't get called when I select the UICollectionViewCell contained in the UICollectionView. What have I missed?

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

UPDATE: return YES in this method collectionView:shouldSelectItemAtIndexPath: will invoke the below two methods. At least that's what was missing on my part. Hope this will help some body... enter image description here

Woke answered 15/5, 2014 at 20:37 Comment(4)
is ".allowsSelection" for your collection view set to YES?Gateshead
@MichaelDautermann. Thanks for your response. ".allowsSelection" is set to "YES".Woke
does the table view cell it's sitting in allow user interaction or selection of the cell itself?Gateshead
the UICollectionView is smaller than the table view cell. When I select the area outside the UICollectionView but inside the table view cell the method didSelectRowAtIndexPath gets called. So yes the selection of the cell works.Woke
F
1

Does the table view's didSelectRowAtIndexPath get called? If so, the table view may be intercepting the touches and not passing them through to the collection view inside. I've never done the solution you are trying to do, but the collection view is inside a scroll view, and it may not be easy to pass the touch info along to the collection view in a way that makes sense, so you may need to disable tapping on the table view cell in order for the collection view to respond to touches.

Fullblown answered 23/10, 2014 at 23:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.