ra1028 / RAReorderableLayout

A UICollectionView layout whitch can move item with drag and drop.
MIT License
867 stars 140 forks source link

swift3 - Duplicated items problem #50

Open fatihyildizhan opened 8 years ago

fatihyildizhan commented 8 years ago

If you drag the B and drop left to the A, you'll get two A's. This problem occurs on demo and actual project.

order 1 order 2
// current:
 func collectionView(_ collectionView: UICollectionView, at: IndexPath, didMoveTo toIndexPath: IndexPath) {
        let book = books.remove(at: (toIndexPath as NSIndexPath).item)
        books.insert(book, at: (toIndexPath as NSIndexPath).item)
    }

// fixed: Is this the right solution ?
 func collectionView(_ collectionView: UICollectionView, at: IndexPath, didMoveTo toIndexPath: IndexPath) {
        let book = books.remove(at: (at as NSIndexPath).item)
        books.insert(book, at: (toIndexPath as NSIndexPath).item)
    }
mjhassan commented 7 years ago

@fatihyildizhan, logically your fix seems correct.