Anil Santo
Anil Santo

Reputation: 195

Assertion failure in UICollectionView when trying to reload data

I get an Error:

    Assertion failure in -[UICollectionViewData numberOfItemsBeforeSection:],/SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionViewData.m


    Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for number of items before section 2 when there are only 1 sections in the collection view'

when i try to reload the collectionview.It works when new sections are added but when i try to remove them it throws an exception.

update:

 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return object.count;

}

 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
if([sortString isEqualToString:@"title"])
    return [Obj.ordered allKeys].count;
else
    return 1;

}

Upvotes: 3

Views: 3341

Answers (1)

Rafał Sroka
Rafał Sroka

Reputation: 40028

Before deleting rows or sections, you have to delete items from your data source array. If your method returns 1 before deleting section then after deleting it should return 0.

Upvotes: 2

Related Questions