ios - Deleting last row from UITableView - Crash with NSInternalInconsistencyError -


i've tried searchable solutions no avail. current deletion code follows:

[self.conversationstableview beginupdates]; [_conversations removeobjectatindex:[indexpath row]]; if ([self.conversationstableview numberofrowsinsection:indexpath.section] == 1) {     [self.conversationstableview deletesections:[nsindexset indexsetwithindex:indexpath.section] withrowanimation:uitableviewrowanimationautomatic]; } else {     [self.conversationstableview deleterowsatindexpaths:@[ indexpath ] withrowanimation:uitableviewrowanimationautomatic]; } [self.conversationstableview endupdates]; 

as can see, deleting datasource in _conversations before deleting section/row - , deleting section if it's last one.

i still crash:

terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'uitableview internal bug: unable generate new section map old section count: 1 , new section count: 0'

i'm out of ideas, unless hacky solution insert invisible section above actual content, don't want do. appreciated.

here numberofsectionsintableview looks like:

- (nsinteger)numberofsectionsintableview:(uitableview *)tableview {     return 1; } 

really weird update: tried hacky way of getting around inserting blank section deleted old one. unexplainable reason still getting error. error insists tableview has new section count of 0 though i've changed code following:

if ([self.conversationstableview numberofrowsinsection:indexpath.row] == 1) {     [self.conversationstableview deletesections:[nsindexset indexsetwithindex:0] withrowanimation:uitableviewrowanimationautomatic];     [self.conversationstableview insertsections:[nsindexset indexsetwithindex:0] withrowanimation:uitableviewrowanimationnone]; } else {     [self.conversationstableview deleterowsatindexpaths:@[ indexpath ] withrowanimation:uitableviewrowanimationautomatic]; } 

completely clueless why happening @ point...

stack trace:

nsinternalinconsistencyexception', reason: 'uitableview internal bug: unable generate new section map old section count: 1 , new section count: 0' *** first throw call stack: (     0   corefoundation                      0x000000010b6bee65 __exceptionpreprocess + 165     1   libobjc.a.dylib                     0x000000010b137deb objc_exception_throw + 48     2   corefoundation                      0x000000010b6becca +[nsexception raise:format:arguments:] + 106     3   foundation                          0x000000010ad844de -[nsassertionhandler handlefailureinmethod:object:file:linenumber:description:] + 198     4   uikit                               0x0000000109bef679 -[_uitableviewupdatesupport(private) _computesectionupdates] + 2858     5   uikit                               0x0000000109c00059 -[_uitableviewupdatesupport initwithtableview:updateitems:oldrowdata:newrowdata:oldrowrange:newrowrange:context:] + 435     6   uikit                               0x00000001098cf912 -[uitableview _endcellanimationswithcontext:] + 12936     7   wontbuyios                          0x000000010819dea8 -[wobmessagesviewcontroller querycontrollerdidchangecontent:] + 88     8   layerkit                            0x0000000108db4ca6 __65-[lyrquerycontroller updatewithobjectidentifiers:changedobjects:]_block_invoke154 + 74     9   libdispatch.dylib                   0x000000010c05249b _dispatch_client_callout + 8     10  libdispatch.dylib                   0x000000010c03bc3c _dispatch_barrier_sync_f_slow_invoke + 284     11  libdispatch.dylib                   0x000000010c05249b _dispatch_client_callout + 8     12  libdispatch.dylib                   0x000000010c03a2af _dispatch_main_queue_callback_4cf + 1738     13  corefoundation                      0x000000010b61ed09 __cfrunloop_is_servicing_the_main_dispatch_queue__ + 9     14  corefoundation                      0x000000010b5e02c9 __cfrunlooprun + 2073     15  corefoundation                      0x000000010b5df828 cfrunlooprunspecific + 488     16  graphicsservices                    0x000000010e33cad2 gseventrunmodal + 161     17  uikit                               0x00000001097a4610 uiapplicationmain + 171     18  wontbuyios                          0x00000001081a6bcf main + 111     19  libdyld.dylib                       0x000000010c08692d start + 1     20  ???                                 0x0000000000000001 0x0 + 1  ) 

insert/deletion code:

- (void)querycontroller:(lyrquerycontroller *)controller         didchangeobject:(id)object             atindexpath:(nsindexpath *)indexpath           forchangetype:(lyrquerycontrollerchangetype)type            newindexpath:(nsindexpath *)newindexpath {     switch (type) {         case lyrquerycontrollerchangetypeinsert: {             [_conversations addobject:object];             [self.conversationstableview insertrowsatindexpaths:@[ newindexpath ] withrowanimation:uitableviewrowanimationautomatic];         }             break;         case lyrquerycontrollerchangetypedelete: {             [_conversations removeobjectatindex:indexpath.row];             if ([self.conversationstableview numberofrowsinsection:indexpath.row] == 1) {                 [self.conversationstableview deletesections:[nsindexset indexsetwithindex:0] withrowanimation:uitableviewrowanimationautomatic];                 [self.conversationstableview insertsections:[nsindexset indexsetwithindex:0] withrowanimation:uitableviewrowanimationnone];             } else {                 [self.conversationstableview deleterowsatindexpaths:@[ indexpath ] withrowanimation:uitableviewrowanimationautomatic];             }             break;         }         default:             break;     } } 

numberofrowsinsection calls _conversations.count. after deleting item in data source array returns wrong value. compare 0 rather 1

beginupdates / endupdates not needed single insert/delete/move operation.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -