Problems extending NSPersistentDocument Core Data Tutorial

  • Hi

    I want to extend the core-data application from the
    NSPersistentDocument core data tutorial with some additional
    functionality. I've added a sheet to manage a tree of departements.
    The Department entity has two additional relationships, a parent and
    an inverse children relationship. I've successfully managed to bind an
    NSTreeController and an NSOutlineView. Now, I want to add an
    NSPopupButton to the new object sheet which allows to choose the
    department for a new employee.

    However, if I launch the application and add some departments and then
    try to add a new employee, the NSPopupButton is not updated (that is,
    it stays empty). If I save the document, reopen it and add a new
    employee, the popup button is properly populated. Below the changes
    I've made in the new Employee Sheet NIB.

    * NSArrayController for the departements
    ** managedObjectContext bound to managedObjectContext of File's Owner
    * NSPopupButton for the departements
    ** Content bound to array controller arrangedObjects
    ** Content Values bound to array controller arrangedObjects key path
    name
    ** Selected Object bound to Object Controller arrangedObjects key path
    department

    If I bind the array controller's managedObjectContext to the
    documentManagedObjectContext of File's Owner, the popup menu is
    populated (I can't complete the sheet because the department is from a
    different managed object context and that is obviously not allowed).
    How can I make sure that the changes from the departments sheet are
    visible in the new object sheet's popup button?

    Thanks
    Simon
  • Ok, I've got part of my question answered (RTFM http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/Articles
    /cdChangeManagement.html#/

    /apple_ref/doc/uid/TP30001201, section Communicating Changes Between
    Contexts). Managed object contexts are not synchronized and that is
    the way how it should be according to the documentation. However, I've
    tried to implement solution 2 from that document (reset second managed
    object context) to no avail. I've reset the second moc but the
    departments still do not show up. Do I have to save the first moc? It
    seems that way (it works when I save before opening the new object
    sheet). That's definitely not what I want. I don't want to force the
    user to save the document just that the departments show up in the new
    object sheet. How can I make the added departments visible in the new
    object sheet?

    Simon

    On Nov 18, 2007, at 9:42 PM, Simon wrote:

    > Hi
    >
    > I want to extend the core-data application from the
    > NSPersistentDocument core data tutorial with some additional
    > functionality. I've added a sheet to manage a tree of departements.
    > The Department entity has two additional relationships, a parent and
    > an inverse children relationship. I've successfully managed to bind
    > an NSTreeController and an NSOutlineView. Now, I want to add an
    > NSPopupButton to the new object sheet which allows to choose the
    > department for a new employee.
    >
    > However, if I launch the application and add some departments and
    > then try to add a new employee, the NSPopupButton is not updated
    > (that is, it stays empty). If I save the document, reopen it and add
    > a new employee, the popup button is properly populated. Below the
    > changes I've made in the new Employee Sheet NIB.
    >
    > * NSArrayController for the departements
    > ** managedObjectContext bound to managedObjectContext of File's Owner
    > * NSPopupButton for the departements
    > ** Content bound to array controller arrangedObjects
    > ** Content Values bound to array controller arrangedObjects key path
    > name
    > ** Selected Object bound to Object Controller arrangedObjects key
    > path department
    >
    > If I bind the array controller's managedObjectContext to the
    > documentManagedObjectContext of File's Owner, the popup menu is
    > populated (I can't complete the sheet because the department is from
    > a different managed object context and that is obviously not
    > allowed). How can I make sure that the changes from the departments
    > sheet are visible in the new object sheet's popup button?
    >
    > Thanks
    > Simon
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today