cocoa touch - Maintain state in a multi view app -
i have appdelegate initiates view controller switches between 2 uiviews.
my question want maintain state. gather done in appdelegate applicationwillterminate. question how access button text , tableview data 2 views , best way persist table data?.
to persist current screen, try using nsuserdefaults:
[[nsuserdefaults standarduserdefaults] setinteger:0 forkey:klastopenedscreenkey];
for others, if you're using core data store , editing store table data access , modification, long save managedobjectcontext, reloading should take care of itself. make sure save data after modifying store code this:
nsmanagedobjectcontext *moc = [self managedobjectcontext]; nserror *error; if (![moc save:&error]) { nslog(@"couldn't save!"); }
edit: if you're not in appdelegate, , haven't set managedobjectcontext instance variable, use line of code instead:
nsmanagedobjectcontext *moc = [[[uiapplication sharedapplication] delegate] managedobjectcontext];
Comments
Post a Comment