InvalidateLayout with invalidateSupplementaryElements and UICollectionViewLayoutInvalidationContext

I am trying to update the footer (optional element). I use the -invalidatelayout method. Based on SO suggestions here . Apple documentation here . I get the following error:

*** Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "invalid context () sent - [UICollectionViewFlowLayout invalidateLayoutWithContext:] is not an instance of type UICollectionViewFlowLayoutInvalidationContext or subclass"

let footer_context = UICollectionViewLayoutInvalidationContext()
footer_context.invalidateSupplementaryElements(ofKind: "ActivitiesSelectMembersFooterView", at: [indexPath])
self.collectionView?.collectionViewLayout.invalidateLayout(with: footer_context)

It looks like the invalidateLayout method expects a UICollectionViewFlowLayoutInvalidationContext instead of a UICollectionViewLayoutInvalidationContext.

I am using Xcode 8 and Swift 3.

My storyboard in Xcode is here -

enter image description here

Next is a footer that has a custom class called ActivitiesSelectMembersFooterView

+4
source share
1 answer

The error message accurately describes the problem. When calling invalidateLayout(with:)in a UICollectionViewFlowLayout object, you need to pass an instance of UICollectionViewFlowLayoutInvalidationContext .

Change this line:

let footer_context = UICollectionViewLayoutInvalidationContext()

For this:

let footer_context = UICollectionViewFlowLayoutInvalidationContext()
+4
source

Source: https://habr.com/ru/post/1661382/


All Articles