I am trying to refresh a Footer ( supplementaryElement). I am using the invalidatelayout
method. Based on SO suggestions here. Apple documentation here.
I am getting the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'the invalidation context () sent to -[UICollectionViewFlowLayout invalidateLayoutWithContext:] is not an instance of type UICollectionViewFlowLayoutInvalidationContext or a subclass'
Implemented Code:
let footer_context = UICollectionViewLayoutInvalidationContext()
footer_context.invalidateSupplementaryElements(ofKind: "ActivitiesSelectMembersFooterView", at: [indexPath])
self.collectionView?.collectionViewLayout.invalidateLayout(with: footer_context)
Looks like invalidateLayout
method is expecting UICollectionViewFlowLayoutInvalidationContext
instead of UICollectionViewLayoutInvalidationContext
.
I am using Xcode 8 and Swift 3.
My Storyboard in Xcode is here -
"Next" is the Footer that has the custom class "ActivitiesSelectMembersFooterView"
The error message accurately describes the problem. When calling invalidateLayout(with:)
on a UICollectionViewFlowLayout object, you need to pass an instance of UICollectionViewFlowLayoutInvalidationContext.
Change this line:
let footer_context = UICollectionViewLayoutInvalidationContext()
To this:
let footer_context = UICollectionViewFlowLayoutInvalidationContext()