Uncheck all items in a pop menu

Hello everybody,

Can’t find a simple method to uncheck all the items of a pop menu at once [sort of my nicePopUpMenu’s uncheckAllItems() ]. Could you help me please?

Check the documentation for the selectItem: instance method of NSPopUpButton class, you’ll have your answer.

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)

OK, so it should be:

my nicePopUpMenu’s selectItem_(missing value)

Thank you!

Yep. Except you dont need the “my” before the binded pop up menu object. Just sending it the message should do.

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)

This does the following : the selected item of the pop menu is blanked (ok, this seems normal but not exactly what I wanted to do) but when I click on it, the items are always checked.

So this does what I don’t want but doesn’t do what I want: leave the selected item as it is and uncheck all items.

You could probably store the current selection either with indexOfSelectedItem or selectedItem, then use selectItem_(missing value), and reselect the item with selectItemAtIndex: or selectItem: (depending on which method you chose to get the selected item).

Of course, I am saying this without knowing the whole context, but I think this is what I understand from your last post. :slight_smile:

Yes, this should restore the current menu item (I’m so sure that I won’t try it now) but my problem is that the check mark is not removed.

Hi,

I guess, you need a repeat loop.

enumerateObjectsUsingBlock of NSArray is a smart method to apply actions to all objects of an NSArray, but I doubt that blocks are available in ASOC.
I tested makeObjectsPerformSelector:withObject: of NSArray, but it does not work

Hmm, I have no more ideas for now… I’ll keep thinking about it and post something if I have any more ideas…

Hi Stefan,

No they aren’t. But of course a loop is always a solution (sigh). Thanks!

It’s not clear to me what you want. Do you just want the check marks gone? Or, do you need the selection to be nil, or both?

To make the check marks go away just use nicePopup’s |menu|()'s setShowsStateColumn_(0)

Ric

Hi Ric, thank you for the answer.

I looked for this setShowsStateColumn_(0) but didn’t find exactly what it does. Does it remove the checkmarks or simply hides them, leaving the menu items in their state?

To answer your question, I have a pop menu with multiple items checked. I want to “reset” this menu by removing all the check marks (the selected item can remain the same, as the pop menu does not put a check mark before the current item when the menu is not deployed, anyway).

setShowsStateColumn only removes the column with the check marks, it doesn’t change the selected items. I was not aware that you could have multiple things selected in an NSPopup button. How did you set it up so that multiple items can be checked at the same time?

Ric

After multiple trials, I unchecked the box “Alters state” of my popUp in Interface Builder.

As far as I can tell, that does the same thing as setShowsStateColumn_(0) does in code.

Ric

And does that solve your problem? Your post kinda suggested that… :slight_smile:

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

No, the problem isn’t solved yet (that is, unless I use a loop). I want the check marks to be removed because the state of the menu items are set to 0, not because they are hidden.

Alright. Well, I don’t see how you can do it without a repeat loop. I don’t think there is a method dedicated for this task, although it would make sense that there would be one…

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

I think you just have to use the loop then. I tried what Stefan was talking about above, using makeObjectsPerformSelector:withObject:, and I got the opposite of what I expected. I tried it like this:

thePopup’s itemArray()'s makeObjectsPerformSelector_withObject_(“setState:”,0). Instead of unchecking everything, it checked everything, and if I look at their states in a loop, they’re all 1. Weird.

Ric

I think the reason that what you want to do isn’t easy, is that you are doing something that isn’t consistent with Apple’s Human Interface Guidelines. Popup’s are only supposed to have one item checked at a time. From the Doc’s:

Don’t use a pop-up menu when more than one simultaneous selection is appropriate. For example, a list of text styles, from which users might choose both bold and italic, should not be displayed in a pop-up menu. In this situation, you should instead use checkboxes or a pull-down menu in which checkmarks appear.

Ric