objective c - NSFetchedResultsController - Serious application error -
in app have nsfetchedresultscontroller
update table in every change in db.
sometime during change went wrong in app , table remain empty no matter (even if change screen , return, table remain empty).
only after turn off app , turn on seems fine again.
i isolate problem error
"coredata: error: serious application error. exception caught delegate of nsfetchedresultscontroller during call -controllerdidchangecontent:. invalid update: invalid number of rows in section 0. number of rows contained in existing section after update (19) must equal number of rows contained in section before update (19), plus or minus number of rows inserted or deleted section (3 inserted, 0 deleted) , plus or minus number of rows moved or out of section (0 moved in, 0 moved out). userinfo (null)"
it seems related un explain difference between row number in "begin update" , "end update",which mean when wrong when deleting or inserting rows.
this kind of hard debug using break point because in happens not often.
any suggestions?
my code :
#pragma mark - nsfetchedresultscontrollerdelegate - (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller { [self.guitableview beginupdates]; } - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id <nsfetchedresultssectioninfo>)sectioninfo atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type { switch(type) { case nsfetchedresultschangeinsert: [self.guitableview beginupdates]; [self.guitableview insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationautomatic]; [self.guitableview endupdates]; break; case nsfetchedresultschangedelete: [self.guitableview beginupdates]; [self.guitableview deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationleft]; [self.guitableview endupdates]; // if (controller.sections.count==0) { // [self alertaboutnothinginmyassetsandpop]; // } break; } } - (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type newindexpath:(nsindexpath *)newindexpath { uitableview *tableview = self.guitableview; sooptioncell *cell; switch(type) { case nsfetchedresultschangeinsert: [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationautomatic]; break; case nsfetchedresultschangedelete: [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationleft]; break; case nsfetchedresultschangeupdate: cell = (sooptioncell *)[tableview cellforrowatindexpath:indexpath]; [self configurecell:cell atindexpath:indexpath animated:yes]; break; case nsfetchedresultschangemove: [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationautomatic]; [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath]withrowanimation:uitableviewrowanimationautomatic]; break; } } - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller{ [self.guitableview endupdates]; }
first, remove of -beginupdates
, -endupdates
calls inside of delegate methods. there should 1 of each. 1 -beginupdates
in -controllerwillchangecontent:
, 1 -endupdates
in -controllerdidchangecontent:
. go far should change other methods examples provided apple instead of writing them yourself.
once discrepancy go away? suspect will.
Comments
Post a Comment