问题描述
使用视图的 indexPathForItemAtPoint,我会得到一个单元格的索引路径,但不会得到 UICollectionReusableView(页眉/页脚)——因为它总是返回 nil.
Using the view's indexPathForItemAtPoint, I will get an index path for a cell, but never a UICollectionReusableView (header/footer) -- as it always returns nil.
推荐答案
您应该制作自己的字典,将索引路径映射到标题视图.在您的 collectionView:viewForSupplementaryElementOfKind:atIndexPath:
方法中,在返回之前将视图放入字典中.在您的 collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:
中,从字典中删除视图.
You should make your own dictionary mapping index paths to header views. In your collectionView:viewForSupplementaryElementOfKind:atIndexPath:
method, put the view into the dictionary before returning it. In your collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath:
, remove the view from the dictionary.
这篇关于如何获取 UICollectionView 标头的索引路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!