2
2014-07-24 11:50:15.925  *** Assertion failure in -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:], /SourceCache/UIKit/UIKit-2935.137/UICollectionViewData.m:787

2014-07-24 11:50:15.927  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionFooter at path <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}'

i have this error message occurs when i scrolling my collection view and i totally loss in mind how could this happen ? any suggestion to help are thankful.

The register

[self.collectionView registerClass:[CollectionViewFooter class]
            forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"CollectionViewFooter"];

The Delegate Method

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    //declare the reusable view of header and footer
    UICollectionReusableView *reusableview = nil;

    CollectionViewFooter *footer=nil;


    if([kind isEqual:UICollectionElementKindSectionFooter])
    {
        footer = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"CollectionViewFooter" forIndexPath:indexPath];

        //attach the footer to reusable view
        reusableview = footer;
    }


    return reusableview;
}

Check by break point, error occur when reach to line [self.collectionView performBatchUpdates:^{

Deeper
  • 129
  • 1
  • 13
  • Supplementary views for collection views are usually related to the collection view header or footer views, maybe something wrong with them if you're using them. – Zhang Jul 24 '14 at 04:03
  • it about the footer view problem, when i scroll to bottom that near to footer, then the error occur. – Deeper Jul 24 '14 at 05:43
  • Did you actually return a footer view in the UIColletionView supplementary view for footer delegate method? - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath I assume you must have registered for using supplementary view when you setup your collection view using - (void)registerClass:(Class)viewClass forSupplementaryViewOfKind:(NSString *)elementKind withReuseIdentifier:(NSString *)identifier – Zhang Jul 24 '14 at 06:32
  • see my updated question, there register method and delegate method. i still try to figure out which part i am did wrong. – Deeper Jul 24 '14 at 06:41
  • Is that if condition suppose to be [kind isEqualToString:...] instead of [kind isEqual:...] ? More importantly though, do you even need the if() check? the dequeReusableSupplementaryView takes a "kind" parameter so it will return you the matching kind already, no? – Zhang Jul 24 '14 at 06:54
  • nope, even i have change it, it still occur *** Assertion failure in -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:] – Deeper Jul 24 '14 at 06:55
  • Are you by any chance using autolayout and attempting to add another view as a subview of UICollectionView ? e.g. [myCollectionView addSubview:someOtherView]; – Zhang Jul 24 '14 at 07:06
  • The first view are parentViewController defined, there are 3 collection view switch as addSubview under segmented control, but now even using one collection view, when scroll to footer, the app will crash. with message " Assertion failure in -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:]" – Deeper Jul 24 '14 at 07:35
  • Do all three collection view use footer views? or is it only one of them use footer view, the other two doesn't, so it crashes when trying to return a footer view? – Zhang Jul 24 '14 at 07:56
  • yes, all of the collection view are re-use the same footer view, it that will cause the problem ? and i check by break point, error happen when reach to this line " [self.collectionView performBatchUpdates:^{ self.batchUpdateFence = @"1"; [self.collectionView reloadItemsAtIndexPaths:singleReloadIndexPathArray]; } completion:^(BOOL finished) {self.batchUpdateFence = @"0";}];" – Deeper Jul 24 '14 at 08:03
  • Did you ever figure this out? I have the exact same problem. – OdieO Sep 28 '14 at 05:09
  • yes, i was found the solution for it. – Deeper Oct 09 '14 at 06:53
  • Possible duplicate of [Issues inserting into UICollectionView section which contains a footer](http://stackoverflow.com/questions/24174456/issues-inserting-into-uicollectionview-section-which-contains-a-footer) – Cristik Jun 01 '16 at 08:06
  • @Deeper Mind sharing your solution? I am experiencing [something similar](http://stackoverflow.com/questions/24924860/no-uicollectionviewlayoutattributes-instance-for-layoutattributesforsupplementar?rq=1) – Genhain Jun 24 '16 at 08:28

0 Answers0