In this post, we will see how to resolve Nested CollectionView doesn’t receive delegate events?
Question:I have a horizontal collection view embedded in the cell of a vertical collection view (a carousel in a feed unit). For some strange reason, the inner scroll view is not receiving scroll view delegate events like scrollViewDidScroll. It does scroll, I just don’t get any notifications about it.
The outer scrollview does, however, receive these events. I suspected the gesture recognizers might be interfering with eachother but I’m not sure. Do you have any idea what might be going wrong here or how I could get the inner collection view to behave normally?
EDIT: I determined that the source of the bug is actually a bug / undefined behavior with compositional layouts with orthogonal scrolling behavior: https://developer.apple.com/forums/thread/127825
Basically they internally create additional horizontal collection views whose delegate events are not propagated upwards. That said, the approach in the accepted answer does work since it’s not using this behavior.
Best Answer:Quick testing — “horizontal collection view embedded in the cell of a vertical collection view” — no trouble getting
scrollViewDidScrollevents for both.
Here’s a quick example:
and this is some sample Debug Console output:
If you have better answer, please add a comment about this, thank you!