UICollectionView crashes randomly because of highlighting issue

女生的网名这么多〃 提交于 2019-12-04 09:22:30

OK. I seem to have solved it. In case anyone faces this problem, here is the fix:

I implemented the following method in my UICollectionViewDelegate:

-(BOOL) collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{

    return NO;
}

This prevents any cell from highlighting, and hence, avoids the crash when the system tries to unhighlight it when it goes off-screen. But, when you do this it also stops calling the didSelectItemAtIndexPath method. So I had to use a UITapGestureRecogniser method to implement cell selection instead.

Hope this helps.

I would suggest returning the following:

- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath{

        return !collectionView.dragging && !collectionView.tracking;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!