josh
josh

Reputation: 1689

Restrict dragging onto specific section

I want to restrict dragging option onto specific section in a single table view. Now I enabled dragging option onto just single section in specific section but what happened when use move successfully cell onto other section where dragging not enabled so it shouldn't move to that section where dragging is not enabled. Kindly see attached image where I enable editing for deleted in first section and dragging for section section and row shouldn't able to move onto first section. I want to perform this in single cell. Is this possible if yes then how? This will be great for me. Thanks in advance. Tableview

Upvotes: 1

Views: 379

Answers (1)

Mick MacCallum
Mick MacCallum

Reputation: 130183

Use targetIndexPathForMoveFromRowAtIndexPath::. It's a UITableViewDelegate method that will allow you to intercept the index path that the user is attempting to drag the cell to. If the section is somewhere that you don't want them to be able to drag the cell, simply return the source index path, and upon release, the cell will bounce back to its original position.

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    if (proposedDestinationIndexPath.section == sectionYouDontWant) {
        return sourceIndexPath;
    }
    return proposedDestinationIndexPath;
}

Upvotes: 4

Related Questions