Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalidateLayout with invalidateSupplementaryElements and UICollectionViewLayoutInvalidationContext

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 -

enter image description here

"Next" is the Footer that has the custom class "ActivitiesSelectMembersFooterView"

like image 666
Jack tileman Avatar asked Nov 20 '16 20:11

Jack tileman


1 Answers

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()
like image 188
jamesk Avatar answered Oct 22 '22 05:10

jamesk