NSArrayController and NStableView Binding

  • Hi,

    I have created a NSArrayController object which has the following
    attributes:

    Class Name: Person
    Keys: personName, expectedRaise
    ContentArray: employees

    employees is a NSMutableArray contains references to Person objects.
    employee is part of MyDocument class(subclass of NSDocument).

    Now my NSTableView has to columns. The 1st column(person Name) is bound to
    ArrangedObjects.personName. The 2nd column(Expected Raise) is bound to
    ArrangedObjects.expectedRaise.

    My window also has to button Add and Remove. On clicking add it adds another
    Person object to ContentArray via (void)insertObject:(Person *)p
    inEmployeesAtIndex:(int)index method in Mydocument class. Similarly for
    Remove.

    Now my Question was that when I double click on a cell in NSTableView to
    edit it what method does it call in the MyDocument class(if any) to reflect
    the edit onto the particular Person object?

    If it does not call a method in MyDocument class how does it change the
    instance variables of the particular Person object being edited? Does each
    cell of the NSTableView have reference to its respective Person Object and
    it just uses an accessor?

    Thanks
  • On Aug 1, 2008, at 6:53 PM, Revant Jain wrote:

    > Now my Question was that when I double click on a cell in
    > NSTableView to
    > edit it what method does it call in the MyDocument class(if any) to
    > reflect
    > the edit onto the particular Person object?
    >
    > If it does not call a method in MyDocument class how does it change
    > the
    > instance variables of the particular Person object being edited?
    > Does each
    > cell of the NSTableView have reference to its respective Person
    > Object and
    > it just uses an accessor?

    The exact sequence is an implementation detail.  Roughly, it invokes
    something like

    [theArrayController setValue:theNewValue
    forKeyPath:@"selection.personName"]  (or .expectedRaise)

    The array controller turns that into a call like

    [[theMyDocumentInstance
    objectInEmployeesAtIndex:indexOfSelectedObject] setValue:theNewValue
    forKeyPath:@"personName"]

    From there, KVC does it's usual job, which is typically to invoke the
    setter (setPersonName:) on your Person object, if that accessor is
    available.

    Cheers,
    Ken
previous month august 2008 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