【发布时间】:2018-03-05 15:49:49
【问题描述】:
我有一个UICollectionView,用户可以在查看每个 Swift 拖放页面后更改单元格的位置。我确定了一种能够更新字符串数组以跟踪此函数中的集合视图的方法:
func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let positionPreviouslyHoldingTheSelectedIndex = list[sourceIndexPath.item]
// put the select index in the intended destination index
list[sourceIndexPath.item] = list[destinationIndexPath.item]
// put the cell/index of the destination index in the selected positions old index
list[destinationIndexPath.item] = positionPreviouslyHoldingTheSelectedIndex
}
但是上面的代码按预期更新了数组,它变得很奇怪,一旦调用moveItemAt,我将如何更新数组/列表。
【问题讨论】:
标签: ios swift drag-and-drop uicollectionview