osx - Core Data: How to update an NSArrayController immediately after adding an NSManagedObject? -


i adding instance in core data. entity represented nsarraycontroller. access newly added instance through controller.

a "skill" instance added , try access through selectaddedobject follows:

-(void)addskill {     [self selectaddedobject:[nsentitydescription insertnewobjectforentityforname:@"skill"                                                           inmanagedobjectcontext:self.managedobjectcontext]]; }  - (void)selectaddedobject:(nsmanagedobject *)addedmo {     [self.sectionarraycontroller setselectedobjects:[nsarray arraywithobject:addedmo]];     nslog(@"selected: %@", [self.sectionarraycontroller valueforkey:@"selectedobjects"]); } 

this seems work if add

[self.managedobjectcontext processpendingchanges]; 

as first line of selectaddedobject:. once that, document seems forget still needs save, , quit app without addition being auto-saved. don't want force onto users!

any ideas on way update array controller in other way? or perhaps add object in way? few earlier answers (e.g. updating nstableview when enitiy added core data) seem bit outdated due changes in osx.

thanks!!

use array controller add object. @ point during configuration, ensure entity set ([self.sectionarraycontroller setentityname:@"skill"]) , of work create , select:

- (void)createandselectnewobject {     skill *addedmo = [self.sectionarraycontroller newobject];      if([self.sectionarraycontroller commitediting]) {          [self.sectionarraycontroller setselectedobjects:[nsarray arraywithobject:addedmo]];         nslog(@"selected: %@", [self.sectionarraycontroller valueforkey:@"selectedobjects"]);     } } 

you should commit edits before changing selection (and change selection if edits committed or there weren't any).


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -