I have tried it with collectionView.reloadData(), but that didn't really work out. What do I do?
Asked
Active
Viewed 1,323 times
2
-
2Somehow, you should use [insertItems(at:)](https://developer.apple.com/reference/uikit/uicollectionview/1618097-insertitems) method. Because of there is no code snippet, i.e it is a generic question, I suggest to check [this article](http://rshankar.com/uicollectionview-demo-in-swift/) -*Insert Cell* section- to check how you can play with it. – Ahmad F Dec 19 '16 at 11:28
-
Your comment should be the answer. – Pedro Paulo Amorim Mar 07 '18 at 18:42
2 Answers
0
If your collectionview has only one section try:
self.collectionView.performBatchUpdates({
let indexSet = IndexSet(integersIn: 0...0)
self.collectionView.reloadSections(indexSet)
}, completion: nil)
As seen on: https://stackoverflow.com/a/42001389/4455570

Gabriel Wamunyu
- 734
- 9
- 25
-1
reloadData does not alter layout nor animates. You have to change position of items, so for example:
func shuffleTwoCells(srcIndex index1: Int, destIndex index2: Int) {
let firstIndexPath = IndexPath(row: Int(index1), section: 0)
let secondIndexPath = IndexPath(row: Int(index2), section: 0)
self.collectionView?.moveItem(at: firstIndexPath, to: secondIndexPath)
}

ingconti
- 10,876
- 3
- 61
- 48