Binding NSMenuItem 'value' or 'title': Accessors not invoked

  • After binding the 'value' (which should show/hide the checkmark) or
    the 'title' of NSMenuItems in my main menu, I find that the bound-to
    accessors only get invoked once, when the app launches.  Therefore,
    subsequent changes are never propagated to the menu.

    My expectation is that the accessors should be invoked whenever the
    menu containing the menu item is clicked, the same as -
    validateMenuItem works.

    I know that I've not misspelled the key names, because if I do
    misspell a key name or if my accessor does not exist, I get a
    complaint in Console and the app crashes on launch.

    Is there some other action I need to do?

    Jerry Krinock
  • I should have added that I can bind the 'enabled' binding of these
    same menu items and it works as expected, invoking the accessor and
    enable/disabling whenever the menu containing the menu item is clicked.
  • On 10/9/07, Jerry Krinock <jerry...> wrote:
    > After binding the 'value' (which should show/hide the checkmark) or
    > the 'title' of NSMenuItems in my main menu, I find that the bound-to
    > accessors only get invoked once, when the app launches.  Therefore,
    > subsequent changes are never propagated to the menu.

      Are your accessors properly enclosed with will/didChangeValueForKey: calls?

    --
    I.S.
  • On 2007 Oct, 09, at 6:54, I. Savant wrote:

    > Are your accessors properly enclosed with will/
    > didChangeValueForKey: calls?

    No they were not, and fixing that fixed the problem.  Thanks again!
  • >> Are your accessors properly enclosed with will/
    >> didChangeValueForKey: calls?
    >
    > No they were not, and fixing that fixed the problem.  Thanks again!

      D'oh! ;-)

      Basically any time something's not "automagically" updating, that's
    the most likely culprit (in my experience, that is). It is *so worth*
    going back over the KVC/KVO documentation any time you run into such a
    problem. It's easy to overlook and if you re-read the rules every time
    you break them, you're more likely to remember them. ;-)

      In this particular case, checking an enabled state wasn't a problem
    because this is checked every time the menu is displayed due to (as
    you guessed) the validation mechanism. The title, however, would not
    be. If you want it to 'notice' this change, proper notifications must
    be sent (KVC/KVO).

    --
    I.S.
previous month october 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