ios - UICollectionView 重新排序不可移动的单元格问题

标签 ios uicollectionview

我正在制作一个带有 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/

相关文章:

ios - 如何在 UICollectionView IOS 中一次只选择一张图像

swift - 如何使用 swift - tvOS 获取 UIcollectionview 单元格中聚焦单元格的 'parent'

iphone - UIAlertView 中的 UITextView 大文本

ios - UIAlertController 处理关闭点击外部 (iPad)

objective-c - 多个按钮调用相同的函数(并且函数知道调用了哪个按钮)

ios - 如果同时使用自动键盘隐藏,则文本字段的清除按钮 (x) 不起作用

ios - 如何在 ios 7 的 "more"uitableview 中更改图标的灰色?

ios - 为 collectionview 重新加载数据

ios - 双击单元格在 iOS9 上不起作用

iOS UI - 在一个屏幕中的 UICollectionView 和 UITableView 之间切换