NSMenuItem: setState not working as expected

  • I have a NSSearchField which is connected to a NSMenu by way of the
    searchMenuTemplate in IB (Interface Builder).  The menu is working
    great in that the recently searched items show up, the two
    NSMenuItems items created to make use of
    NSSearchFieldClearRecentsMenuItemTag and
    NSSearchFieldNoRecentsMenuItemTag all work well and as expected.  I
    followed "Introduction to Search Fields" to accomplish this.

    The last feature I wanted to add to this menu is to allow the user to
    select which column (all or pick an individual column from the menu)
    to filter content,  somewhat similar to what is in iTunes and its
    search box with a choice of "All" or "Album" or "Artist", etc.  I
    added three NSMenuItems to the NSMenu and titled them accordingly and
    gave each a different tag starting at 1 and ending at 3.  All three
    share the same target.  The first NSMenuItem is set to a state of
    "On".  The other two are set to a state of "Off".

    Here is a sample of state change.  There are three NSMenuItems items
    (in addition to the above mentioned items):
    - Search All (initial state set to "On" via IB)
    - Command (intial state set to "Off" via IB)
    - Connection (ditto)

    Run application.  Pull down menu from the search field and choose,
    say, Connection.  The target method logs the state of "Search All" as
    NSOnState.  The target method sets the state for "Connection" to
    NSOnState.  It then sets the state of "Search All" to NSOffState with
    the intent of removing the check mark beside it, leaving "Connection"
    as the only item with a check mark. I then log the state of "Search
    All" after the state change and at this point and it shows
    NSOffState.  So far so good.  I pull the menu down again and both
    "Search All" and "Connection" have check marks.  Not good.  I also
    notice that if I click back on "Search All", to turn it to an on
    state, the logging, which logs the state before and after the call to
    setState:, shows no change in state!  Like it's not responding to the
    message being sent.

    I suspect there is something going on with how the NSSearchField is
    using this menu that I don't understand.

previous month september 2007 next month
          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
Go to today