objective c - Core Data, populating mandatory relationship from a newly created NSManagedObject -



objective c - Core Data, populating mandatory relationship from a newly created NSManagedObject -

this should easy, how hard can be.

i have document based core info application simple info model.

i have "node" entity parent/children relationship controlled nstreecontroller, , viewed through nsoutlineview. "node" has non optional (to one) relationship entity type "nodeproperties" managed nsarraycontroller. have nsmanagedobject sublasses both of entities. document class has outlets bound both tree controller , array controller instances.

my problem how ensure that, when new "node" created user interface action in outline view, relation suitable (pre-existing) nodeproperties object populated.

approaches have tried / considered:

let tree controller create "node" (from add:, addchild: actions) , populate relationship nodeproperties object in "node" subclass awakefrominsert method. problem cannot find means of accessing nodeproperties object within "node"s awakefrominsert. "appropriate" nodeproperties object available method in document class, accessing document object node awakefrominsert method seems break principles of mvc, , have read shared document object not safe in drag , drop operation (which in case creates new node object)

write add: , addchild: action methods in document class , invoke these end user actions instead of tree controller (my drag , drop back upwards in document class). within these methods invoke add: , addchild: methods in tree controller, set nodeproperties relationship on newly created node. problem don't know how inquire tree controller give me reference newly created node? have tried using selectedobjects method parent, , comparing parents children before , after add together new node. children content not alter @ time - perhaps delayed update?

as variant of 2, don't utilize tree controller add:/addchild: methods @ all, instead create node entity object in document add:/addchild: methods using tree controllers selectedojects parent. don't since seems doing behind tree controllers back, , have setcontent: each time created root objects.

i have considered possibility of observing creation of newly created node, don't know observe accomplish that.

someone must have done before - trawled no avail. help, advice, guidance welcome.

ok after much trawling , experimentation reply variant of 3. document creates new node, populating mandatory relationship, in add together , addchild action methods, , inserts node tree controller using method

nstreecontroller insertobject:atarrangedobjectindexpath:

for interested, addchild method in document class. has few specifics info model

- (ibaction)addchildaction:(id)sender { nsarray *indexpaths = [nodetreecontroller selectionindexpaths]; nsarray *selectedobjects = [nodetreecontroller selectedobjects]; (nsuinteger = 0; < [indexpaths count]; i++) { qvxpandnode *parentnode = [selectedobjects objectatindex:i]; if ((parentnode) && ([parentnode.ismaster boolvalue])) // can add together nodes under master node { qvxpandnode *creatednode = [self createpopulatednode]; // dont belelieve below safe when >1 selected, // since adding new node result in tree paths changing? // hmmm want back upwards multiple selection addition?? [nodetreecontroller insertobject:creatednode atarrangedobjectindexpath:[[indexpaths objectatindex:i] indexpathbyaddingindex:[parentnode.children count]]]; } } }

you see unsure whether set sec , later children @ right path if >1 rows selected before calling action.

the addsibling method more complicated need calculate lastly index path value, otherwise similar. can reproduce if wants see it, key populating mandatory relationship in new tree node in document class , tell tree controller exactly in tree want insert it.

objective-c core-data model-view-controller nsoutlineview nstreecontroller

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -