UICollectionView crash on unhighlightAllItems

前端 未结 4 1055
别那么骄傲
别那么骄傲 2021-02-09 01:26

I\'ve gotten several crash reports related to a UICollectionView in iOS 7. I\'m not able to consistently recreate this crash.

Exception Type:  SIGSEGV
Exception         


        
4条回答
  •  孤街浪徒
    2021-02-09 01:40

    I had this problem, though slightly different crash. Fixed by holding off any reloadData until the highlight is cleared. While toostn's suggestion would fix the issue, it is useful to be able to reloadData whilst scrolling, but doesn't make much sense when highlighting - as you have your finger on a cell.

    implement the following UICollectionViewDelegate methods:

    - (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
        self.allowReload = NO;
        return YES;
    }
    
    
    - (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath {
        self.allowReload = YES;
        [self reloadIfNecessary]; // calls reloadData if it is necessary to do so!
    }
    

提交回复
热议问题