Binding to one specific object of an NSArrayController

  • Hi,

    In my application I have a submenu which represents the content of
    an NSArrayController. When I add an object via the controllers add:
    method a new menu item is created. But when I change the value of a
    property from inside the table, this change is not reflected to the
    menu items. Therefore I bound the NSArrayController's selection.name
    keypath to the menu item's title when the menu item is added to the
    menu. Unfortunetly selection.name is the wrong keypath, because the
    title of all the menu items is the name of the selected item in the
    table. So my question is: Is there a way to bind each NSMenuItem's
    title to exactly one object managed by the NSArrayController?

    Best regards,
    Michael

    --
    Psssst! Schon vom neuen GMX MultiMessenger gehört?
    Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger?did=10
  • on 12/31/07 9:56 AM, <M.Varlik...> purportedly said:

    > In my application I have a submenu which represents the content of
    > an NSArrayController. When I add an object via the controllers add:
    > method a new menu item is created. But when I change the value of a
    > property from inside the table, this change is not reflected to the
    > menu items. Therefore I bound the NSArrayController's selection.name
    > keypath to the menu item's title when the menu item is added to the
    > menu. Unfortunetly selection.name is the wrong keypath, because the
    > title of all the menu items is the name of the selected item in the
    > table. So my question is: Is there a way to bind each NSMenuItem's
    > title to exactly one object managed by the NSArrayController?

    No. Why can't you bind the menu title in the same way you have bound the
    table column value?

    Best,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • Hi Michael

    > In my application I have a submenu which represents the content of
    > an NSArrayController. When I add an object via the controllers add:
    > method a new menu item is created. But when I change the value of a
    > property from inside the table, this change is not reflected to the
    > menu items. Therefore I bound the NSArrayController's selection.name
    > keypath to the menu item's title when the menu item is added to the
    > menu. Unfortunetly selection.name is the wrong keypath, because the
    > title of all the menu items is the name of the selected item in the
    > table. So my question is: Is there a way to bind each NSMenuItem's
    > title to exactly one object managed by the NSArrayController?
    >
    If you think that you need to bind to individual items in the
    NSArrayController,
    then perhaps you need to access the contents of the controller using
    - (id)arrangedObjects;
    This will return you the NSArray of objects maintained by the array
    controller.
    You can iterate through this array and bind to each of the menu items.
    I am not sure if this is an elegant method, but it works.

    Regards
    Shripada
  • On 2007 Dec, 31, at 20:39, Shripada Hebbar wrote:

    > This will return you the NSArray of objects maintained by the array
    > controller.
    > You can iterate through this array and bind to each of the menu items.
    > I am not sure if this is an elegant method, but it works.

    I would say that it is not elegant, and also more work and more
    confusing than doing it without bindings.  Your data is only flowing
    in one of the two directions; i.e. the user cannot add or delete items
    using menu, so you're missing that "advantage" of bindings too.

    I would definitely ^not^ use bindings in this case.
previous month december 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
31            
Go to today