1
如何查看IndexView在CollectionView中的第一個位置?我需要將某個元素移至第一個位置:CollectionView中第一個元素的IndexPath
collectionView.moveItem(at: collectionView.indexPath(for: cell)!,
to: *????*))
如何查看IndexView在CollectionView中的第一個位置?我需要將某個元素移至第一個位置:CollectionView中第一個元素的IndexPath
collectionView.moveItem(at: collectionView.indexPath(for: cell)!,
to: *????*))
使用IndexPath(item: Int, section: Int)
。在這種情況下,這將是
IndexPath(item: 0, section: 0)
你甚至可以定義一個zero
靜態變量爲CGRect
和其他正在做
extension IndexPath {
static let zero = IndexPath(item: 0, section: 0)
}
,並用它作爲
collectionView.moveItem(at: collectionView.indexPath(for: cell)!, to: .zero))
這種做法給了我下面的錯誤:'NSInternalInconsistencyException',原因:'嘗試移動索引路徑( {length = 2,path = 0 - 0})不存在 - 節中只有0項0更新之前' 而且我100%確信,收集之後的移動稱爲實際數據。 –
'更新前0節中只有0項'它表示collectionView在更新前沒有元素。 –
Double checked - collectionView在調用移動方法時有5個元素 –