UITableView: how to disable dragging of items to a specific row?

This is exactly what the UITableViewDelegate method

-tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

is for. Will it suit your purposes? Here's the documentation.


The previous answers and the documentation (see this and this, as mentioned in the other answers) are helpful but incomplete. I needed:

  • examples
  • to know what to do if the proposed move is not okay

Without further ado, here are some

Examples

Accept all moves

- (NSIndexPath *)tableView:(UITableView *)tableView
    targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath
                         toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    return proposedDestinationIndexPath;
}

Reject all moves, returning the row to its initial position

- (NSIndexPath *)tableView:(UITableView *)tableView
    targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath
                         toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    return sourceIndexPath;
}

Reject some moves, returning any rejected row to its initial position

- (NSIndexPath *)tableView:(UITableView *)tableView
    targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath
                         toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    if (... some condition ...) {
        return sourceIndexPath;
    }
    return proposedDestinationIndexPath;
}