1

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];

}

4

2 回答 2

1

嗯,有一个简短的答案和一个长答案。

简短的回答:你不能做你正在做的事情,我很惊讶它适用于其他行。

长答案:您尝试做的事情与用户“通常”期望发生的事情背道而驰。IE。如果您将一行从一个地方“移动”到另一个地方,它将“移动”而不是合并。正如其他人指出的那样,错误消息说明了很多。当您删除行时,行数从 51 变为 50。移动行时,数字必须相同。

解决方案:解决方案可能很简单,虽然我自己没有尝试过。尝试稍微延迟或其他方式触发所有这些删除和更新任务。这样,移动的行就会完成它的工作,到那时更新任务将准备好删除行并更新数据,以便您可以在目标中显示合并的行。

于 2013-06-03T10:48:17.570 回答
0

检查替换单元格前后的行数。

显示您本身的错误表示替换前的行数不等于替换后的行数。

于 2013-06-03T10:29:04.227 回答