1

我想将拖动选项限制到单个表格视图中的特定部分。现在我启用了拖动选项到特定部分的单个部分,但是当使用成功移动单元格到未启用拖动的其他部分时发生了什么,因此它不应该移动到未启用拖动的部分。请查看附件图像,其中我启用了在第一部分中删除的编辑和拖动部分部分和行不应该移动到第一部分。我想在单个单元格中执行此操作。如果是的话,这可能吗?这对我来说会很棒。提前致谢。 表视图

4

1 回答 1

1

使用targetIndexPathForMoveFromRowAtIndexPath::。这是一个 UITableViewDelegate 方法,它允许您拦截用户试图将单元格拖到的索引路径。如果该部分位于您不希望他们能够拖动单元格的地方,只需返回源索引路径,释放后,单元格将弹回其原始位置。

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    if (proposedDestinationIndexPath.section == sectionYouDontWant) {
        return sourceIndexPath;
    }
    return proposedDestinationIndexPath;
}
于 2013-08-29T12:00:05.480 回答