NSArrayController & NSTableView selectionIndexes bug

  • Hi,

    I'm writing an app that has a table containing data on one side of a
    split view, with its columns bound to an NSArrayController, and an
    NSView subclass on the other side. It's not a document-based app so I
    have an AppController class instantiated in IB with two outlets - one
    for the the NSView subclass, the other for the arrayController. I can
    add and delete rows from the table just fine, and display the info from
    the current selection in the custom view, all ok.

    The problem I'm having is that whenever I create two or more rows in the
    table and switch between them the following appears in the debug console:

    2008-02-05 21:20:29.770 GanttXv4[22988:10b] Error setting value for key
    path selectionIndexes of object <NSArrayController: 0x134dd0>[object
    class: NSMutableDictionary, number of selected objects: 1] (from bound
    object <NSTableView: 0x129a30> with object ID 432 in Nib named
    MainMenu.nib): [<NSCFString 0x191950> valueForUndefinedKey:]: this class
    is not key value coding-compliant for the key selection.

    At first I thought this was related to the fact that I've bound
    arrayController.arrangedObjects to an NSMutableArray in the custom view,
    as I want it to display the data for the whole table, not just the
    current selection, but I've rolled my code back to before that happened
    and it persists. It doesn't seem to affect the program's execution but I
    don't want to run into problems later.

    So my questions are:
    - Any idea what causes that problem?
    - Am I going about the overall problem the right way?

    Thanks

    Rob
  • Hi Rob,

    When you see something receiving valueForUndefinedKey, it's probable
    that the wrong object is receiving the message. In this case,
    "selection" is an NSArrayController key, but it's being sent to an
    NSString. Beyond that, I'm not sure, without seeing some code or
    getting more detail on how things are set up. Somebody else might have
    more ideas.

    How are you adding the objects to the array? Via -[NSArrayController
    add] or another method? When you say the array is "in" the custom
    view, do you mean it's an iVar in that object? The array should
    probably be an iVar in your AppController, the array controller's
    contentArray should be bound to it, and the table columns and custom
    view bound to the array controller.

    Wil

    On Feb 5, 2008, at 1:45 PM, Rob Redpath wrote:

    > Hi,
    >
    > I'm writing an app that has a table containing data on one side of a
    > split view, with its columns bound to an NSArrayController, and an
    > NSView subclass on the other side. It's not a document-based app so
    > I have an AppController class instantiated in IB with two outlets -
    > one for the the NSView subclass, the other for the arrayController.
    > I can add and delete rows from the table just fine, and display the
    > info from the current selection in the custom view, all ok.
    >
    > The problem I'm having is that whenever I create two or more rows in
    > the table and switch between them the following appears in the debug
    > console:
    >
    > 2008-02-05 21:20:29.770 GanttXv4[22988:10b] Error setting value for
    > key path selectionIndexes of object <NSArrayController:
    > 0x134dd0>[object class: NSMutableDictionary, number of selected
    > objects: 1] (from bound object <NSTableView: 0x129a30> with object
    > ID 432 in Nib named MainMenu.nib): [<NSCFString 0x191950>
    > valueForUndefinedKey:]: this class is not key value coding-compliant
    > for the key selection.
    >
    > At first I thought this was related to the fact that I've bound
    > arrayController.arrangedObjects to an NSMutableArray in the custom
    > view, as I want it to display the data for the whole table, not just
    > the current selection, but I've rolled my code back to before that
    > happened and it persists. It doesn't seem to affect the program's
    > execution but I don't want to run into problems later.
    >
    > So my questions are:
    > - Any idea what causes that problem?
    > - Am I going about the overall problem the right way?
    >
    > Thanks
    >
    > Rob
  • > - Any idea what causes that problem?

    What is your array controller’s selectionIndexes binding set to? It
    looks like this is your problem.

    -Ben