1
votes

I have a UICollectionView. Its cell has a UICollectionView inside of it.

enter image description here

I can detect when the cell containing the collectionView is tapped (via didSelectItemAtIndexPath). However, I cannot detect when the cells of the collectionView inside the cell (as depicted by the individual sun icons) are tapped.

User-interaction is enabled on everything. And I've tried overriding the hitTest of the collectionView as described here.

Update: I tried this again in a simple test project and it worked fine. However in my current project for some reason the inner-most nested collectionView (with the sun icons) does not appear in the view debugger.

enter image description here

Notice I made the collectionView background blue and its cells pink. And they do not appear when view debugged, although they appear in the running app?

2
Have you set the delegate of the UICollectionViewCell that contains a UICollectionView to self? Meaning that you should subclass a UICollectionViewCell and set up the UICollectionView inside that subclass and set the delegate of that UICollectionView to the UICollectionViewCell. Also, you shouldn't need to be messing around with hit testing. Very rarely is there a case where the UIResonder chain needs some massive intervention and with this one, I doubt you need to go farther than setting delegation correctly.Larry Pickles
@Loxx Yes, the delegate of the inner collectionView is set to the cell that it resides invikzilla
Hmm, let me pull up and old project and see how I worked around this. I'll post here soonLarry Pickles
@Loxx thanks, that would be very helpful :)vikzilla
Disable "Cancels Touches in View" for CollectionView in Storyboard.ogres

2 Answers

0
votes

I've done this before... but it's going to be a little hard to explain. The short answer is TapGestures.

So I had the tableView through storyboard drawn. The collection view was added programatically.

For TableView cellforRow, I called UITableViewCell subclass. Which I passed the rootView as a delegate. Which called a CollectionViewClass. This is where the actual items for the cell are being drawn and added to the collection view. At this point I have the rootdelegate. For each item i add a tapGesture.

    let tap = UITapGestureRecognizer(target: self, action: #selector(viewTapped))

So each item now has a tap gesture inside it. Now in my view that was drawing i can call the rootview with which cell was tapped.

func viewTapped() {
    tapDelegate?.milestoneTapped(passID) //tapDelegate = RootView
}

I hope this helps.

0
votes

Once I changed from using XIBs for my cells to using regular cells from storyboard this problem did not occur.