UICollectionView crashes when deleting section

2019-08-30 11:20发布

问题:

When using this code

  - (void)actionSheet:(UIActionSheet *)actionSheet 
             clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        if (buttonIndex == 0) {

            [self removeCompany:companySelectedInActionSheet]; 

            NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:
                          indexPathSelectedInActionSheet.section];
            NSLog(@"IndexSet to delete from collection view: %@",indexSet);
            [self.collectionView deleteSections:indexSet]; 
        }
    }

my app crashes sometimes (10% of the time) with this error:

*** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit_Sim/UIKit-2903.2/UICollectionView.m:3700

Any thoughts on what might be wrong?

Is the action sheet, which is presented before the deletion, a potential problem?

Do I need to dismiss it manually before deleting the collection view section?

回答1:

set your table view delegate to nil on viewDidDisappear