Monday, 15 July 2013

ios - Consistency between the same database accessed in the appdelegate and a view controller -



ios - Consistency between the same database accessed in the appdelegate and a view controller -

i've been working core info , uimanageddocument lately, , have questions.

i've uitableviewcontroller in open uimanageddocument. here download info tableviewcotroller , save info database , update tableview. when come in main screen via home button , open app again, want work info database in appdelegate . in appropriate method in appdelegate, open database, fetch entities want , alter properties in objects want. now, works, manage open database , objects want database.

my problem occours when i'm done changing info database in appdelegate. because after appdelegate method completed, seek refetch info in tableview same database, @ point of time database hasn't registered changes made in method called in appdelegate. i've tried calling savetourl overwriting method on uimanageddocument right after changes made within appdelegate , ive tried save: method on managedobjectcontext. what's right way of saving changes database gets updated?

ps: i'm writing on ipad, havnt managed upload code, i'll upload later.

thanks

that right way - create changes in nsmanagedobjectcontext save. remember savetourl asynchronous, problem save has not completed time perform fetch in table view. that's completion block comes in. maybe have completion block set property in table view causes fetch happen. like

// appdelegate [self.maindatabase savetourl:self.maindatabase.fileurl forsaveoperation:uidocumentsaveforoverwriting completionhandler:^(bool success) { if (success) { mytableview.context = self.maindatabase.managedobjectcontext; } }]; // tableview - (void)setcontext:(nsmanagedobjectcontext *)newcontext { _context = newcontext; nsarray *fetchresults = [_context executefetchrequest:somefetchrequest error:&error]; // update model etc. }

ios core-data nsmanagedobjectcontext save uimanageddocument

No comments:

Post a Comment