UICollectionView: How to get the header view for a section?

前端 未结 4 1981
臣服心动
臣服心动 2021-01-31 09:15

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 vie

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 09:50

    UPDATE

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

    ORIGINAL

    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.

提交回复
热议问题