我正在制作一个带有 iOS 9 超酷重新排序功能的 UICollectionView。我可以通过在数据源的函数 - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
中为该索引路径返回 No 来使单元格不可移动。
但是,我发现单元格可以被可移动的元素替换,这不是预期的。
例如,
We cannot move the 3rd item (screenshot).
But it is able to be the destination index path for other cell to move to(screenshot).
对于真正修复第 3 个单元格有什么好的想法吗?
最佳答案
假设无法移动位于 indexpath = {x,y} 的项目。尝试使用以下委托(delegate)方法。
collectionView(_:targetIndexPathForMoveFromItemAtIndexPath:toProposedIndexPath:)
如果建议的索引路径等于 {x,y}
,则您为项目提供所需的索引路径。例如 {x+1,y}
来自文档:
During the interactive moving of an item, the collection view calls this method to see if you want to provide a different index path than the proposed path. You might use this method to prevent the user from dropping the item in an invalid location. For example, you might prevent the user from dropping the item in a specific section.
关于ios - UICollectionView 重新排序不可移动的单元格问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34847270/