larryryu / LSSwipeToDeleteCollectionViewLayout

The UICollectionViewLayout subclass adds swipe to delete functionality to a collectionview
MIT License
41 stars 4 forks source link

[LSSwipeToDeleteCollectionViewLayout cellDidTranslate] app crash iOS 9.2.1 #12

Closed mitulmarsonia closed 6 years ago

mitulmarsonia commented 6 years ago

Hi, Nice Library, Getting crash iOS 9.2.1. I have attached fabric screenshot please help me out. screenshot 2018-04-23 17 41 25

larryryu commented 6 years ago

Thanks! Could you share more details or maybe include some of the code in your app. I tried running this project as is and not getting a crash. The crash is occurring somewhere in UIKit which makes it harder to track down.

mitulmarsonia commented 6 years ago

I have find out issue. Getting nil value selectedIndexPath when try to swipe right.

- (void)cellDidTranslate{
    if ([self.swipeToDeleteDelegate respondsToSelector:@selector(swipeToDeleteLayout:cellDidTranslateWithOffset:)]) {
        if (selectedIndexPath != nil){
            UICollectionViewLayoutAttributes *unselectedAttribute = [super layoutAttributesForItemAtIndexPath:selectedIndexPath];
            UICollectionViewLayoutAttributes *selectedAttribute = [self layoutAttributesForItemAtIndexPath:selectedIndexPath];
            UIOffset offset = UIOffsetMake(selectedAttribute.center.x - unselectedAttribute.center.x, selectedAttribute.center.y - unselectedAttribute.center.y);
            [self.swipeToDeleteDelegate swipeToDeleteLayout:self cellDidTranslateWithOffset:offset];

        }
    }
}

I have just added nil condition. it's working fine. Thanks @larryryu