ios - UITableViewCell header display drawing issue with NSFetchedResultsController delegate using NSManagedContextDidSaveNotification implementation -


i have implemented nsfetchedresultscontroller delegate nsmanagedcontextdidsavenotification push managed objects changes nsmanagedobjectcontext connected common nspersistentstorecoordinator.

when managed objects first batch imported , after nsfetchedresultscontrollerdelegate methods called, result of cell drawing contains section looks this:

enter image description here

it display/drawing bug section header gets drawn cell. header , cell actual valid header , cell appear further down.

it happens first time managed objects created in batch. if restart app , managed objects imported controller displays fine it's import process, typical nsfetchedresultscontrollerdelegate implementation (pasted below):

- (void)controllerwillchangecontent:(nsfetchedresultscontroller *)controller {     [_tableview beginupdates]; } - (void)controller:(nsfetchedresultscontroller *)controller didchangesection:      (id <nsfetchedresultssectioninfo>)sectioninfo       atindex:(nsuinteger)sectionindex       forchangetype:(nsfetchedresultschangetype)type {     switch(type) {         case nsfetchedresultschangeinsert:             [_tableview insertsections:                 [nsindexset indexsetwithindex:sectionindex]                 withrowanimation:uitableviewrowanimationfade]; break;         case nsfetchedresultschangedelete:             [_tableview deletesections:                 [nsindexset indexsetwithindex:sectionindex]                 withrowanimation:uitableviewrowanimationfade]; break;         case nsfetchedresultschangeupdate:             nslog(@"change section"); break;         case nsfetchedresultschangemove:             nslog(@"move setion"); break;     } } - (void)controller:(nsfetchedresultscontroller *)controller      didchangeobject:(id)anobject atindexpath:     (nsindexpath *)indexpath forchangetype:(nsfetchedresultschangetype)type   newindexpath:(nsindexpath *)newindexpath {     switch(type) {         case nsfetchedresultschangeinsert:             [_tableview insertrowsatindexpaths:               [nsarray arraywithobject:newindexpath]               withrowanimation:uitableviewrowanimationfade];             break;         case nsfetchedresultschangedelete:             [_tableview deleterowsatindexpaths:               [nsarray arraywithobject:indexpath]                withrowanimation:uitableviewrowanimationfade];             break;         case nsfetchedresultschangeupdate:             [self configurecell:[_tableview cellforrowatindexpath:indexpath]              atindexpath:indexpath];             nslog(@"change object"); break;         case nsfetchedresultschangemove:             [_tableview deleterowsatindexpaths:               [nsarray arraywithobject:indexpath]                withrowanimation:uitableviewrowanimationfade];             [_tableview insertrowsatindexpaths:               [nsarray arraywithobject:newindexpath]                withrowanimation:uitableviewrowanimationfade];             nslog(@"move object"); break;     } } - (void)controllerdidchangecontent:(nsfetchedresultscontroller *)controller {     [_tableview endupdates]; } 

the thing tried implementing refresh needslayout , reloaddata detecting when it's first batch import , calling them doesn't rid of display issue. halp!

edit:

 - (void)setupfetchedresultscontroller {     nsfetchrequest *fr = [nsfetchrequest fetchrequestwithentityname:@"object"];     nssortdescriptor *sd1 = [nssortdescriptor sortdescriptorwithkey:@"attribute" ascending:yes];     nssortdescriptor *sd2 = [nssortdescriptor sortdescriptorwithkey:@"attribute2" ascending:yes];     nspredicate *predicate = [nspredicate predicatewithformat:@"self.relationship.attribute3 == true"];     [fr setpredicate:predicate];     [fr setsortdescriptors:@[sd1, sd2]];     _frc = [[nsfetchedresultscontroller alloc] initwithfetchrequest:fr managedobjectcontext:_moc sectionnamekeypath:@"attribute" cachename:nil];     [_frc setdelegate:self];     nserror *error; if (![_frc performfetch:&error]) nslog(@"%@", error.description); } 

edit: here code fixed issue:

- (void)subscribetonotifications {     [[nsnotificationcenter defaultcenter] addobserver:self        selector:@selector(mergemanagedobject:)        name:nsmanagedobjectcontextdidsavenotification       object:nil]; } - (void)mergemanagedobject:(nsnotification *)notification {     dispatch_async(dispatch_get_main_queue(), ^{         // block needed sent on main thread!         [_managedobjectcontext            mergechangesfromcontextdidsavenotification:notification];     }); } 

did try implementing/adjusting code follows?

  • call - reloadsections:withrowanimation: when nsfetchedresultschangeupdate on section changes,
  • - movesection:tosection: when nsfetchedresultschangemove happens on section changes,
  • - moverowatindexpath:toindexpath: when nsfetchedresultschangemove triggered on controller:didchangeobject:, and
  • - reloadrowsatindexpaths:withrowanimation: when nsfetchedresultschangeupdate triggered on controller:didchangeobject:.

if doesn't help, step methods , on thread they're called. often, view bugs happen when view updates called on threads other main thread.

last, did try using childcontexts?


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -