In my application,I am performing reordering of cells but I am concatenating selected cells with each other
I have some cells and I am doing some cell animation i.e. user can select any cell and drag to any cell present in my table and after dragging these two cells are replaced by one cell that is created with these two cells. But my problem is when I am trying to replace the last cell, it is not allowing me to do and the cell which I am trying to drag is added at the bottom without replacing the last cell and it is only happening for last cell
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (50) must be equal to the number of rows contained in that section before the update (51), 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, 0 moved out).
2013-06-03 15:16:33.636 QuestionPro[6565:1d003] *** 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 (50) must be equal to the number of rows contained in that section before the update (51), 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, 0 moved out).'
Here is my code
- (void)endedDragGestureWithTranslationPoint:(CGPoint)translation {
[self updateFrameOfDraggedCellForTranlationPoint:translation];
self.draggedCell.layer.shouldRasterize = NO;
[(UITableViewCell *)self.draggedCell setHighlighted:NO animated:YES];
UITableViewCell *oldDraggedCell = [self.draggedCell retain];
NSIndexPath *blankIndexPath = [self.indexPathBelowDraggedCell retain];
CGRect blankCellFrame = oldDraggedCell.frame;
CGPoint blankCellCenter = {
.x = CGRectGetMidX(blankCellFrame),
.y = CGRectGetMidY(blankCellFrame)
};
NSIndexPath *rowToMoveTo = [tableView indexPathForRowAtPoint:blankCellCenter];
if ( rowToMoveTo ) {
CGRect rectForIndexPath = [tableView rectForRowAtIndexPath:rowToMoveTo];
if (dragGesture.state == UIGestureRecognizerStateFailed ){
rectForIndexPath = [tableView rectForRowAtIndexPath:self.indexPathBelowDraggedCell];
}
NSIndexPath * secIndex = [blankIndexPath copy];
[UIView animateWithDuration:0.25 delay:0 options:(UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState) animations:^{
oldDraggedCell.frame = rectForIndexPath;
[self dragTableViewController:self hideDraggableIndicatorsOfCell:oldDraggedCell];
} completion:^(BOOL finished) {
[self dragTableViewController:self removeDraggableIndicatorsFromCell:oldDraggedCell];
[oldDraggedCell removeFromSuperview];
[oldDraggedCell release];
}];
if (dragGesture.state == UIGestureRecognizerStateEnded && secIndex.row != rowToMoveTo.row ){
[tableView beginUpdates];
[self joinTableViewCellsAtFirstRow:rowToMoveTo.row andSecondRow:secIndex.row];
NSArray * delArray = [[NSArray alloc] initWithObjects:secIndex , nil];
NSArray * rfrArray = [[NSArray alloc] initWithObjects:secIndex , nil];
[tableView deleteRowsAtIndexPaths:delArray withRowAnimation:UITableViewRowAnimationNone];
SALTableCellView * toggledCell = (SALTableCellView *)[tableView cellForRowAtIndexPath:rowToMoveTo];
if ( toggledCell.selectedImage && activateDelegate ){
[activateDelegate spotMarkedWithTitle:toggledCell.title andValue:toggledCell.shownValue andColor:[UIColor clearColor]];
}
[delArray release];
[rfrArray release];
[tableView endUpdates];
[self recalculateTapSumm];
[self refreshData];
}
else
hiddenCell.hidden = NO;
[secIndex release];
[tableView scrollRectToVisible:rectForIndexPath animated:YES];
}
[blankIndexPath release];
[oldDraggedCell release];
}