0
votes
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString* CellIdentifier = @"MessageCellIdentifier";

    MessageTableViewCell* cell = (MessageTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = [[MessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    Message* message = [self.dataModel.messages objectAtIndex:indexPath.row];


        [cell setMessage:message];

    return cell;

}

I am developing an chat application in which i am getting exception when sending and receiving messages happening at the same time.The following is the exception message

Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-2380.17/UITableView.m:1070 2013-04-30 16:55:14.314 [2689:907] 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 (19) must be equal to the number of rows contained in that section before the update (17), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

- (int)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataModel.messages count];
}

    - (void)didSaveMsg:(NSMutableArray *)array1
    {
        self.dataModel.messages = array1;

        [tableview insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:array1.count-1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];

        [self scrollToNewestMessage];
    }



- (void)scrollToNewestMessage
{

    dispatch_after(DISPATCH_TIME_NOW, dispatch_get_main_queue(), ^(void){
    NSIndexPath* indexPath = [NSIndexPath indexPathForRow:(self.dataModel.messages.count - 1) inSection:0];

    [tableview scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
    });

    [tableview reloadData];
    [[DBModel database]updateMessageCount1:mobileNo cnt:@"0"];


}
1
once show your numberOfRows Method ??Manu
The exception is with deleting or adding rows. Just Check your numberOfRows method ? Once paste that.Manu
it is with adding rowsXcode
Just paste your numberOfRows method in your questionManu
Can you paste your code how you are adding rows ?Manu

1 Answers

0
votes

The error message is fairly self explanatory - you are telling the table view you want to insert a single cell, but in the table's datasource are then saying it has two extra cells to display (19 instead of 17).

The problem almost certainly isn't in the code you've posted, it will be either in the numberOfRows method of your datasource, or in the code at the point at which you insert the extra cell.