objective c - NSInternalInconsistency Exception in UITableView -
- (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 developing chat application in getting exception when sending , receiving messages happening @ same time.the following 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 uncaught exception 'nsinternalinconsistencyexception', reason: 'invalid update: invalid number of rows in section 0*.
the number of rows contained in existing section after update (19) must equal number of rows contained in section before update (17), plus or minus number of rows inserted or deleted section (1 inserted, 0 deleted) , plus or minus number of rows moved or out of 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"]; }
the error message self explanatory - telling table view want insert single cell, in table's datasource saying has 2 cells display (19 instead of 17).
the problem isn't in code you've posted, either in numberofrows method of datasource, or in code @ point @ insert cell.
Comments
Post a Comment