ios - NSFetchedResultsController update/insert removing cell from UITableview -


using nsfetchedresultscontroller auto update uitableview facing issue. when trying add/edit device whole cell vanished every time.

here bunch of code

// nsfetchedresultscontroller delegate methods  - (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller {     [self.atableview beginupdates]; }  - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:(id <nsfetchedresultssectioninfo>)sectioninfo            atindex:(nsuinteger)sectionindex forchangetype:(nsfetchedresultschangetype)type {     uitableview *tableview = self.atableview;      switch(type) {         case nsfetchedresultschangeinsert:             [tableview insertsections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade];             break;          case nsfetchedresultschangedelete:             [tableview deletesections:[nsindexset indexsetwithindex:sectionindex] withrowanimation:uitableviewrowanimationfade];             break;          default:             return;     } }  - (void)controller:(nsfetchedresultscontroller *)controller didchangeobject:(id)anobject        atindexpath:(nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type       newindexpath:(nsindexpath *)newindexpath {     uitableview *tableview = self.atableview;      switch(type) {         case nsfetchedresultschangeinsert:             [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade];             break;          case nsfetchedresultschangedelete:             [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];             break;          case nsfetchedresultschangeupdate:             if(system_version_greater_than_or_equal_to(@"9.0"))                 [tableview reloadrowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];             else                 [tableview reloaddata];             break;          case nsfetchedresultschangemove:             [tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath] withrowanimation:uitableviewrowanimationfade];             [tableview insertrowsatindexpaths:[nsarray arraywithobject:newindexpath] withrowanimation:uitableviewrowanimationfade];             break;     } }  - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller {     [self.atableview endupdates]; }  // fetch data coredata  -(nsfetchedresultscontroller *)loadforumdata {  if (_fetchedforumcontroller != nil) {     return _fetchedforumcontroller; }  nsfetchrequest *fetchrequest = [[nsfetchrequest alloc] init]; nsentitydescription *entity = [nsentitydescription entityforname:@"socialwall" inmanagedobjectcontext:self.managedobjectcontext]; [fetchrequest setentity:entity];  nssortdescriptor *sortdescriptor = [[nssortdescriptor alloc] initwithkey:@"datetime" ascending:no]; [fetchrequest setsortdescriptors:[[nsarray alloc] initwithobjects:sortdescriptor, nil]];  nspredicate *predicate = [nspredicate predicatewithformat:@"(eventid == %@)",self.appdelegate.currentevent.entityid]; [fetchrequest setpredicate:predicate];  fetchrequest.fetchlimit = _range+10; fetchrequest.fetchoffset = 0; // start range  nsfetchedresultscontroller *thefetchedresultscontroller = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fetchrequest managedobjectcontext:self.managedobjectcontext sectionnamekeypath:nil cachename:nil]; [thefetchedresultscontroller setdelegate:self];  _fetchedforumcontroller = thefetchedresultscontroller; [_fetchedforumcontroller performfetch:nil]; return _fetchedforumcontroller;  } 

here o/p i'm getting on device/simulator after editing cell . please check attached simulator screenshort - http://i.stack.imgur.com/lumph.png


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -