I have a UITableView where each cell contains a UICollectionView.
I can scroll the UITableView vertically and scroll the nested UICollectionView horizontally, however I cannot select a UICollectionViewCell in the UICollectionView.
Selection is disabled in the UITableView, and enabled (the default state) in the UICcollectionView.
The UICollectionView's collectionView:didSelectItemAtIndexPath: is simply never called.
The way I was able to solve this was to add a tap gesture recognizer to the cell to handle the tap manually, rather than rely on the didSelectRowAtIndexPath which does not get called:
Swift
let tapRecognizer = UITapGestureRecognizer(target: self, action: "cellTapped:")
tapRecognizer.numberOfTapsRequired = 1
cell.addGestureRecognizer(tapRecognizer)
Objective-C
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapped:)];
tapRecognizer.numberOfTapsRequired = 1;
[cell addGestureRecognizer:tapRecognizer];
You can now handle the cell being tapped in the cellTapped: method, and you can get the reference to the cell that was tapped via tapRecognizer.view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With