如何获取 UICollectionView 标头的索引路径? [英] How to get the index path of a UICollectionView header?

查看:40
本文介绍了如何获取 UICollectionView 标头的索引路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用视图的 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 标头的索引路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆