uitableview - NSFetchedResultsController with custom cells -


i'm using nsfetchedresultscontroller , have no idea how fix current problem. headers in table view cells rather real headers, because don't want headers stick @ top while scrolling.

the message pretty clear it:

coredata: error: serious application error.  exception caught delegate of nsfetchedresultscontroller during call -controllerdidchangecontent:.  invalid update: invalid number of rows in section 1.  number of rows contained in existing section after update (2) must equal number of rows contained in section before update (0), 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). userinfo (null) 

but number of rows in section after insertion of 1 row needs 2! how can let table view know this? i'm doing stuff this:

indexpath = [nsindexpath indexpathforrow:indexpath.row + 1                                insection:section];  newindexpath = [nsindexpath indexpathforrow:newindexpath.row + 1                                   insection:section]; 

but in particular case doesn't work, after first crash works should, because that's time 2 cells inserted while 1 core data itself.

i have found solution problem!

i check if it's first time when cell nsfetchedresultscontroller being added through nsfetchedresultscontroller delegate (didchangeobject:), if is, manually add row.

snippet:

- (void)controller:(nsfetchedresultscontroller *)controller    didchangeobject:(id)anobject        atindexpath:(nsindexpath *)indexpath      forchangetype:(nsfetchedresultschangetype)type       newindexpath:(nsindexpath *)newindexpath {     nsinteger section = 1;     indexpath = [nsindexpath indexpathforrow:indexpath.row + 1                                    insection:section];      nsmutablearray *newindexpaths = [nsmutablearray array];     id <nsfetchedresultssectioninfo> sectioninfo = [controller.sections objectatindex:0];     if ([sectioninfo numberofobjects] == 1) {         newindexpath = [nsindexpath indexpathforrow:newindexpath.row                                           insection:section];         [newindexpaths addobject:newindexpath];     }      newindexpath = [nsindexpath indexpathforrow:newindexpath.row + 1                                       insection:section];     [newindexpaths addobject:newindexpath];      switch(type) {         case nsfetchedresultschangeinsert:             [self.tableview insertrowsatindexpaths:newindexpaths                                   withrowanimation:uitableviewrowanimationfade];             break;         case nsfetchedresultschangedelete:             [self.tableview deleterowsatindexpaths:[nsarray arraywithobject:indexpath]                                   withrowanimation:uitableviewrowanimationfade];             break;         default:             break;     } } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -