Search code examples
uicollectionviewuicollectionviewlayout

UICollectionView exception in UICollectionViewLayoutAttributes from iOS7


I have done a View in CollectionView with CustomLayout. In iOS6 it worked great but iOS7 it throws an exception like this.

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:

'layout attributes for supplementary item at index path ( {length = 2, path = 0 - 0}) changed from CustomSupplementaryAttributes: 0xd1123a0 index path: (NSIndexPath: 0xd112580 {length = 2, path = 0 - 0}); element kind: (identifier); frame = (0 0; 1135.66 45); zIndex = -1; to CustomSupplementaryAttributes: 0xd583c80 index path: (NSIndexPath: 0xd583c70 {length = 2, path = 0 - 0}); element kind: (identifier); frame = (0 0; 1135.66 45); zIndex = -1; without invalidating the layout'


Solution

  • You need to invalidate the existing layout before updating, see the end of the error message:

    without invalidating the layout'

    [collectionViewLayout invalidateLayout];
    

    Apple Documentation for UICollectionViewLayout