grillbiff / DragAndDropTableView

A UITableView where cells can be rearranged by drag and drop.
MIT License
55 stars 13 forks source link

Drag a cell to a non authorized section #7

Closed boazin closed 9 years ago

boazin commented 9 years ago

First of all - Awesome package. Thanks a lot!

I have section 0 that allows reordering of cells. Section 1 - doesn't allow. The thing is when the user drags a cell "too low" (his intention is to set it the last cell in section 0 but he "misses") I get a crash:

*** Assertion failure in -[DragAndDropTableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3347.44/UITableView.m:1623
2015-06-09 09:44:52.725 Cookila copy[23234:619162] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 1 moved out).'

How can I avoid it without getting all the sections in the swap game

boazin commented 9 years ago

Found it. I needed to add the following. (You might wanna find some clever way to get it into the demo because it is is not common code, I had a hard time finding it)

- (NSIndexPath *)tableView:(UITableView *)tableView
targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath
       toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    if ([sourceIndexPath section] != [proposedDestinationIndexPath section]) {
            proposedDestinationIndexPath = sourceIndexPath;
    }
    return proposedDestinationIndexPath;
}

Thanks again!

grillbiff commented 9 years ago

Hi, thanks for the input. I'll have a look at it.