Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created April 22, 2020 03:41
Show Gist options
  • Save SunXiaoShan/e509e54ee7db9a96f574437ae1765b95 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/e509e54ee7db9a96f574437ae1765b95 to your computer and use it in GitHub Desktop.
func updateDataIndex(from fromIndexPath: IndexPath, to toIndexPath: IndexPath) {
let fromPosition = fromIndexPath.item
let toPosition = toIndexPath.item
let selected = cellDataList[fromPosition] as Int
DispatchQueue.main.async {[weak self] in
self?.cellDataList.remove(at: fromPosition)
var newindex = toPosition
if (newindex > self?.cellDataList.count ?? 0) {
newindex = self?.cellDataList.count ?? 0
}
self?.cellDataList.insert(selected, at: newindex)
self?.collectionView.reloadData()
UIView.performWithoutAnimation {
self?.collectionView.reloadSections(IndexSet(integersIn: 0...0))
}
}
}
func getCollectionViewColumnMaxCount() -> Int {
return ViewController.columnCount
}
func getCollectionViewRowMaxCount() -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
let maxCount = getCollectionViewColumnMaxCount() * getCollectionViewRowMaxCount()
let bufferCount = maxCount - (self.cellDataList.count % maxCount)
return self.cellDataList.count + bufferCount
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment