Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

}

like image 693
Anil Santo Avatar asked Feb 19 '26 23:02

Anil Santo


1 Answers

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.

like image 75
Rafa de King Avatar answered Feb 22 '26 11:02

Rafa de King



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!