bind tableview to arraycontroller

  • Step by step I try to master the kvc-kvo-bindings matter.
    Now I have:
        NSArrayController bound to an NSArray in a class in my program
        NSTableView bound to the NSArrayController as follows:
          columns of the table are bound to fields in the objects held by
    the array.

    The problem I am wrestling with: how to see the tableview reacting to
    changes in the array.

    After the discussions in this group I refrained from explicitely
    invoking kvo on the array in my class. It turns out the
    NSArrayController does get the changes, even if these are not at once
    visible in the tableview.
    But if I touch the column header in the tableview then all of a sudden
    the contents becomes visible. If in IB I select off for the 'enabled'
    state in the 'control' part of the table view attributes, then the
    visual updating does not occur.
    One further point to note: clicking in the first column did not update
    the view, though I cannot see a difference in binding with the other
    columns!

    My conclusion therefore: obviously am I doing something wrong in the
    interaction between the tableview and the arraycontroller. The
    controller apparently has received new content but not signalled that
    to the tableview; the latter changing when prodded into action by the
    click in the column header.

    Someone who knows what exactly is going on? I have read the XCode
    documentation in the "Cocoa Binding Programming Topics" but could not
    solve it from that text.

    Hans van der Meer
  • Your NSArray needs to be an array of KVC compliant objects. Is this the case?

    Do you have the NSTableColumn's value binding set to the controller
    key "arrangedObjects" and the model key path set to an attribute of
    your KVC class?

    You could use a CoraData object to do some of the heavy lifting for you.

    Adam

    On 2/23/08, Hans van der Meer <hansm...> wrote:
    > Step by step I try to master the kvc-kvo-bindings matter.
    > Now I have:
    > NSArrayController bound to an NSArray in a class in my program
    > NSTableView bound to the NSArrayController as follows:
    > columns of the table are bound to fields in the objects held by
    > the array.
    >
    > The problem I am wrestling with: how to see the tableview reacting to
    > changes in the array.
    >
    > After the discussions in this group I refrained from explicitely
    > invoking kvo on the array in my class. It turns out the
    > NSArrayController does get the changes, even if these are not at once
    > visible in the tableview.
    > But if I touch the column header in the tableview then all of a sudden
    > the contents becomes visible. If in IB I select off for the 'enabled'
    > state in the 'control' part of the table view attributes, then the
    > visual updating does not occur.
    > One further point to note: clicking in the first column did not update
    > the view, though I cannot see a difference in binding with the other
    > columns!
    >
    > My conclusion therefore: obviously am I doing something wrong in the
    > interaction between the tableview and the arraycontroller. The
    > controller apparently has received new content but not signalled that
    > to the tableview; the latter changing when prodded into action by the
    > click in the column header.
    >
    > Someone who knows what exactly is going on? I have read the XCode
    > documentation in the "Cocoa Binding Programming Topics" but could not
    > solve it from that text.
    >
    > Hans van der Meer
    >