Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 17, 2012, 04: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, 07:56 PM   #2
Red Menace
macrumors 6502
 
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 Yosemite (10.10) / Xcode 6.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old Dec 17, 2012, 08:14 PM   #3
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: 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.
mfram is offline   0 Reply With Quote
Old Dec 17, 2012, 09: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, 10: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, 11:21 PM   #6
Red Menace
macrumors 6502
 
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 Yosemite (10.10) / Xcode 6.1 / RubyMotion FTW
Red Menace is offline   1 Reply With Quote
Old Dec 18, 2012, 07: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

Similar Threads
thread Thread Starter Forum Replies Last Post
NSPopUpButton Question... blackenedheart Mac Programming 8 Sep 5, 2013 07:42 AM
NSPopUpButton Question... blackenedheart Mac Applications and Mac App Store 1 Sep 3, 2013 08:18 PM
OS X Service item to display selected text in large type? jent OS X 0 Oct 23, 2012 01:20 AM
OS X bug - Finder forgets the selected item arrangement jvpython OS X 10.8 Mountain Lion 10 Oct 16, 2012 12:30 AM
NSPopupButton Bindings knightlie Mac Programming 0 Jun 4, 2012 12:32 PM

Forum Jump

All times are GMT -5. The time now is 05:39 AM.

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

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