Help: Data Modelling, NSTreeController and NSBrowser

  • Hi all,

    I did a fair amount of googling last night trying to figure out how
    to successfully instantiate an NSTreeController. I understand, from
    this, that it's not without problems. However I cannot even get the
    application to launch if I've instantiated one in the Nib file.

    Let me preface this by saying, "Any help would be greatly
    appreciated...".

    The application: "Core Data Application" - not document based.
    The model (so far is fairly basic):

    I have an entity defined called Category which has:
    + Attributes:
    - name (String)
    + Relationships:
    - category [toOne, Category optional]
    - subcategories [toMany, Category, optional]

    From within Interface Builder I've instantiated an NSTreeController
    with bindings:
    - Entity: Category (Automatically prepares content)
    - Children keypath: subcategories
    - Predicate: category == nil
    - managedObjectContext: (Bind ticked)
      - Bind to: AppDelegate
      - modelKeyPath: managedObjectContext
    And the NSBrowser:
    - content:
      - Bind to: TreeController
      - controller key: arrangedObjects
    - contentValues:
      - Bind to: TreeController
      - controller key: arrangedObjects
      - Model key path: name

    The problem I'm getting, which I can't figure out, is how to resolve
    the following runtime error.

    2006-10-03 04:05:06.670 TestApp[21868] *** -[NSTreeController
    presentError:]: selector not recognized [self = 0x35be00]
    2006-10-03 04:05:06.670 TestApp[21868] *** NSRunLoop ignoring
    exception '*** -[NSTreeController presentError:]: selector not
    recognized [self = 0x35be00]' that raised during posting of delayed
    perform with target 384660 and selector 'invokeWithTarget:'

    Any ideas?

    Is there something I've not bound? I couldn't find any documentation
    or example projects involving NSTreeController and NSBrowser.

    Thanks.

    Btw, I've also tried just binding the NSBrowser's value but that
    doesn't work either.

    with regards,
    --

    Lachlan Deck
  • On Oct 2, 2006, at 9:36 PM, Lachlan Deck wrote:

    > I have an entity defined called Category which has:
    > + Attributes:
    > - name (String)
    > + Relationships:
    > - category [toOne, Category optional]
    > - subcategories [toMany, Category, optional]
    >
    > From within Interface Builder I've instantiated an NSTreeController
    > with bindings:
    > - Entity: Category (Automatically prepares content)
    > - Children keypath: subcategories
    > - Predicate: category == nil
    > - managedObjectContext: (Bind ticked)
    > - Bind to: AppDelegate
    > - modelKeyPath: managedObjectContext
    > And the NSBrowser:
    > - content:
    > - Bind to: TreeController
    > - controller key: arrangedObjects
    > - contentValues:
    > - Bind to: TreeController
    > - controller key: arrangedObjects
    > - Model key path: name
    >

    I don't know if this is the problem but in my NSBrowser I also have
    - selectionIndexPaths
      - Bind to: TreeController
      - Controller Key: selectionIndexPaths

    John
  • Hi John,

    On 04/10/2006, at 1:54 PM, John Harte wrote:

    > On Oct 2, 2006, at 9:36 PM, Lachlan Deck wrote:
    >
    >> I have an entity defined called Category which has:
    >> + Attributes:
    >> - name (String)
    >> + Relationships:
    >> - category [toOne, Category optional]
    >> - subcategories [toMany, Category, optional]
    >>
    >> From within Interface Builder I've instantiated an
    >> NSTreeController with bindings:
    >> - Entity: Category (Automatically prepares content)
    >> - Children keypath: subcategories
    >> - Predicate: category == nil
    >> - managedObjectContext: (Bind ticked)
    >> - Bind to: AppDelegate
    >> - modelKeyPath: managedObjectContext
    >> And the NSBrowser:
    >> - content:
    >> - Bind to: TreeController
    >> - controller key: arrangedObjects
    >> - contentValues:
    >> - Bind to: TreeController
    >> - controller key: arrangedObjects
    >> - Model key path: name
    >>
    >
    > I don't know if this is the problem but in my NSBrowser I also have
    > - selectionIndexPaths
    > - Bind to: TreeController
    > - Controller Key: selectionIndexPaths

    Thanks very much for the suggestion. Unfortunately, I'm still getting
    the same error.

    Any other ideas? What bindings do you have?

    Thanks.

    with regards,
    --

    Lachlan Deck
  • On Oct 4, 2006, at 2:01 AM, Lachlan Deck wrote:

    > Hi John,
    >
    > On 04/10/2006, at 1:54 PM, John Harte wrote:
    >
    >> On Oct 2, 2006, at 9:36 PM, Lachlan Deck wrote:
    >>
    >>> I have an entity defined called Category which has:
    >>> + Attributes:
    >>> - name (String)
    >>> + Relationships:
    >>> - category [toOne, Category optional]
    >>> - subcategories [toMany, Category, optional]
    >>>
    >>> From within Interface Builder I've instantiated an
    >>> NSTreeController with bindings:
    >>> - Entity: Category (Automatically prepares content)
    >>> - Children keypath: subcategories
    >>> - Predicate: category == nil
    >>> - managedObjectContext: (Bind ticked)
    >>> - Bind to: AppDelegate
    >>> - modelKeyPath: managedObjectContext
    >>> And the NSBrowser:
    >>> - content:
    >>> - Bind to: TreeController
    >>> - controller key: arrangedObjects
    >>> - contentValues:
    >>> - Bind to: TreeController
    >>> - controller key: arrangedObjects
    >>> - Model key path: name
    >>>
    >>
    >> I don't know if this is the problem but in my NSBrowser I also have
    >> - selectionIndexPaths
    >> - Bind to: TreeController
    >> - Controller Key: selectionIndexPaths
    >
    > Thanks very much for the suggestion. Unfortunately, I'm still
    > getting the same error.
    >
    > Any other ideas? What bindings do you have?

    Here are the steps I used to get a document based browser to work:

    Steps to create an NSBrowser view with core data.

    New Project

    Core Data Document-based Application

    Edit Model (MyDocument.xcdatamodel)
    Add Entity
      Add Attribute: "name"
      Type: String
      Default Value: "name"

      Add Relationship: "parent"
      Destination: "Entity"

      Add Relationship: "children"
      Destination: "Entity"
      To-Many Relationship
      Inverse: "parent"

    Open MyDocument.nib
    Add NSTreeController to nib
      Attributes
      Mode: Entitiy
      Entity Name: "Entity"
      Child Key Path: "children"
      Binding
      Parameters
        managedObjectContext
        Bind To: File's Owner (MyDocument)
        Model Key Path: managedObjectContext

    Remove NSTextField from window
    Add NSBrowser
      Bindings
      Browser Content
        content
        Bind To: NSTreeController
        Controller Key: arrangedObjects
        Model Key Path: Leave Blank
        contentValues
        Bind To: NSTreeController
        Controller Key: arrangedObjects
        Model Key Path: "name"
        selectionIndexPaths
        Bind To: NSTreeController
        Controller Key: selectionIndexPaths
        Model Key Path: Leave Blank
    Add Button
      Attributes
      Title: "Add"
      Connection
      Target NSTreeController's add: action
      Binding
      Availability
        enabled
        Bind To: NSTreeController
        Controller Key: canAdd
        Model Key Path: Leave Blank
    Add Button
      Attributes
      Title: "Add Child"
      Connection
      Target NSTreeController's addChild: action
      Binding
      Availability
        enabled
        Bind To: NSTreeController
        Controller Key: canAddChild
        Model Key Path: Leave Blank

    I tried it with a non document based project and it worked.

    Hope this helps.

    John
  • Thanks John,

    On 06/10/2006, at 1:36 AM, John Harte wrote:

    > Here are the steps I used to get a document based browser to work:
    >
    > Steps to create an NSBrowser view with core data.
    >
    > <...>
    > I tried it with a non document based project and it worked.
    >
    > Hope this helps.

    Yep. Seems to work with non-document based projects (substituting
    NSTreeController's Bind To: 'File's Owner (MyDocument)' for
    'MyApplication_AppDelegate')

    Thanks very much.

    with regards,
    --

    Lachlan Deck
previous month october 2006 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 31          
Go to today