lukescott / DraggableCollectionView

Extension for the UICollectionView and UICollectionViewLayout that allows a user to move items with drag and drop. --- HELP WANTED --- Looking for maintainer and help with the experimental branch.
MIT License
549 stars 175 forks source link

Crashes on longPress with more than one section #41

Closed oldmancoyote1 closed 10 years ago

oldmancoyote1 commented 10 years ago

This has been wonderfully useful, but when I added a second section, it crashes on a longPress in: - (NSIndexPath *)indexPathForItemClosestToPoint:(CGPoint)point

I suspect that I am missing something really basic in my implementation. A FlowLayoutDemo with sections would probably clear up my error.

Relevant Code in indexPathForItemClossestToPoint:

    NSInteger items = [self.collectionView numberOfItemsInSection:i];
    NSIndexPath *nextIndexPath = [NSIndexPath indexPathForItem:items inSection:i];
    UICollectionViewLayoutAttributes *layoutAttr;
    CGFloat xd, yd;
    if (items > 0) {

CRASHES HERE-->>>>>> layoutAttr = [self.collectionView.collectionViewLayout layoutAttributesForItemAtIndexPath:nextIndexPath];

There are no are error messages in the debugger.

After longPressing in section 1, item 2: items = 3, nextIndexPath = 1,3 . Perhaps the problem is because of zero based counting, the last valid indexPath is 1,2.

I would greatly appreciate some help here.

Thanks