UICollectionView Decoration and Supplementary views can not be moved

前端 未结 5 2046
耶瑟儿~
耶瑟儿~ 2021-02-01 07:40

In UICollectionView decoration and supplementary views seem to be a big mystery. There seems to be next to no example code at the moment. I managed to get both type

5条回答
  •  时光取名叫无心
    2021-02-01 07:56

    I had a similar symptom. My problem was that I had accidentally included the supplementary view's reuseID instead of the kindID when creating my custom layout.

    Specifically I had this (Wrong)

    UICollectionViewLayoutAttributes *attributes = 
      [UICollectionViewLayoutAttributes
        layoutAttributesForSupplementaryViewOfKind:myViewReuseID
        withIndexPath:sectionIndexPath];
    

    When I should have this (Right)

    UICollectionViewLayoutAttributes *attributes = 
      [UICollectionViewLayoutAttributes
        layoutAttributesForSupplementaryViewOfKind:myViewKindID
        withIndexPath:sectionIndexPath];
    

    This meant that prepareForReuse was never getting called, and my old views never went away. Instead they kept piling up.

提交回复
热议问题