Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Dreamspinner

macrumors member
Original poster
Dec 17, 2012
39
0
In my OS X Cocoa app, I'm using an NSPopupButton to present the user with a list of choices. When an item is selected, it isn't marked.

Code:
  [baudButton removeAllItems];
  [baudButton addItemWithTitle:(@"Baud")];
  [baudButton addItemWithTitle:(@"600")];
  [baudButton addItemWithTitle:(@"1200")];

How to fix it?
 

mfram

Contributor
Jan 23, 2010
1,309
344
San Diego, CA USA
You could try to jump start the process.

Code:
[baudButton selectItemAtIndex:1]

Later you can read the state with:

Code:
[baudButton indexOfSelectedItem]

Also, make sure you made a connection to the right thing with Xcode. You could have made a connection to a specific cell instead of the whole pop-up button.
 

Dreamspinner

macrumors member
Original poster
Dec 17, 2012
39
0
I am going to guess you are talking about a checkmark - for that, you can set the state of the NSMenuItem.

Thanks. Yes, a check mark would be good. I'll have to dig into how to use ValidateMenuItem I think. It seems like it's going to be a little messy if the user changes selection, and I have to find the checked item and un-set it, the set the new one. I sort of bogggled that it doesn't happen automagically:(. But I'm a newbie to Cocoa.
 

Dreamspinner

macrumors member
Original poster
Dec 17, 2012
39
0
You could try to jump start the process.

Code:
[baudButton selectItemAtIndex:1]

Later you can read the state with:

Code:
[baudButton indexOfSelectedItem]

Also, make sure you made a connection to the right thing with Xcode. You could have made a connection to a specific cell instead of the whole pop-up button.

Thanks. I think we have a misunderstanding :confused:. I have no problem getting the selected menu item. I want to mark it as selected (check mark, change color, highlight the item).

The connection is to the whole button.
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
Colorado, USA
It seems like it's going to be a little messy if the user changes selection, and I have to find the checked item and un-set it, the set the new one. I sort of bogggled that it doesn't happen automagically

There can be multiple checked items (and ways to use them), so what gets checked (or not) is up to you. For a single item you would be keeping track of the selection anyway, so typically your action would uncheck the current/old setting and check the new one - see Using Menu Item States.
 

Dreamspinner

macrumors member
Original poster
Dec 17, 2012
39
0
There can be multiple checked items (and ways to use them), so what gets checked (or not) is up to you. For a single item you would be keeping track of the selection anyway, so typically your action would uncheck the current/old setting and check the new one - see Using Menu Item States.

Thanks for the URL. I'm sure that will come in handy!

There are multiple items. Actually, setting the NSButton's type to popup accomplished my goal.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.