Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 17, 2012, 03:01 PM   #1
Dreamspinner
macrumors member
 
Join Date: Dec 2012
NSPopupButton selected item

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?
Dreamspinner is offline   0 Reply With Quote
Old Dec 17, 2012, 06:56 PM   #2
Red Menace
macrumors regular
 
Join Date: May 2011
Location: Littleton, Colorado, USA
I am going to guess you are talking about a checkmark - for that, you can set the state of the NSMenuItem.
__________________
MacBook Pro / OS X Mavericks (10.9.2) / Xcode 5.1 / [and various (much) older stuff keeping dust off the shelves]
Red Menace is online now   0 Reply With Quote
Old Dec 17, 2012, 07:14 PM   #3
mfram
macrumors 6502a
 
Join Date: Jan 2010
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.
mfram is offline   0 Reply With Quote
Old Dec 17, 2012, 08:55 PM   #4
Dreamspinner
Thread Starter
macrumors member
 
Join Date: Dec 2012
Quote:
Originally Posted by Red Menace View Post
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 is offline   0 Reply With Quote
Old Dec 17, 2012, 09:05 PM   #5
Dreamspinner
Thread Starter
macrumors member
 
Join Date: Dec 2012
Quote:
Originally Posted by mfram View Post
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 . 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.
Dreamspinner is offline   0 Reply With Quote
Old Dec 17, 2012, 10:21 PM   #6
Red Menace
macrumors regular
 
Join Date: May 2011
Location: Littleton, Colorado, USA
Quote:
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.
__________________
MacBook Pro / OS X Mavericks (10.9.2) / Xcode 5.1 / [and various (much) older stuff keeping dust off the shelves]
Red Menace is online now   1 Reply With Quote
Old Dec 18, 2012, 06:44 AM   #7
Dreamspinner
Thread Starter
macrumors member
 
Join Date: Dec 2012
Quote:
Originally Posted by Red Menace View Post
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.
Dreamspinner is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:59 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC