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

问题描述

有一种方法可以通过indexPath(UICollectionView cellForItemAtIndexPath:)获取单元格.但我找不到一种方法来获取一个补充视图,如页眉或页脚,在创建后.有什么想法吗?

There is a method to get a cell by indexPath (UICollectionView cellForItemAtIndexPath:). But I can"t find a method to get one of the supplementary views like a header or footer, after it has been created. Any ideas?

推荐答案

更新

从 iOS 9 开始,您可以使用 -[UICollectionViewsupplementaryViewForElementKind:atIndexPath:] 按索引路径获取补充视图.

UPDATE

As of iOS 9, you can use -[UICollectionView supplementaryViewForElementKind:atIndexPath:] to get a supplementary view by index path.

最好的办法是制作自己的字典,将索引路径映射到补充视图.在您的 collectionView:viewForSupplementaryElementOfKind:atIndexPath: 方法中,在返回之前将视图放入字典中.在您的 collectionView:didEndDisplayingSupplementaryView:forElementOfKind:atIndexPath: 中,从字典中删除视图.

Your best bet is to make your own dictionary mapping index paths to supplementary 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:如何获取部分的标题视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 01:47