Setting the items of anÃ?NSPopUpButton programmatically


#1

i’m starting within RubyCocoa, although i’ve been using Cocoa-Java, i
want to setup the items of an NSPopUpButton programmatically.

the related named ib_outlets is called “:choixTheme”

if i list all the associated methods by :

            ctmethods=@choixTheme.methods
            ctmethods.each { |m| p "choixTheme #{m}"}

i never get even the “titleOfSelectedItem” nor “indexOfSelectedItem”

why ?

if i try :

@choixTheme.addItem(“Unbelievable”)
i get an error :
/Library/Frameworks/RubyCocoa.framework/Versions/A/Resources/ruby/osx/ob
jc/oc_wrapper.rb:17:in `NSApplicationMain’: NSApplicationMain -
RBException_OSX::OCMessageSendException - NSPopUpButton#addItem: -
methodSignature is nil. (OSX::OCException)

then, what’s the correct way to setup all the items of a NSPopUpButton
programmatically ?


#2

On Feb 4, 2006, at 1:23, Une bévue wrote:

if i try :

@choixTheme.addItem(“Unbelievable”)
i get an error :

That’d be because (as far as I can tell) it doesn’t have an “addItem”
method. :slight_smile:

then, what’s the correct way to setup all the items of a NSPopUpButton
programmatically ?

	itemArray = ["Unbelievable","Believable"]
	@choixTheme.removeAllItems
	@choixTheme.addItemsWithTitles(itemArray)
	@choixTheme.selectItemWithTitle(itemArray[0])

I “removeAllItems” because there are some in it when I create it in
InterfaceBuilder, and I just didn’t care to bother figuring out how to
place a completely empty pop-up button. :slight_smile: Also, I sometimes refresh
it, and just emptying it and refilling from scratch is easier than
modifying what’s there.

I’m sure there are other ways to do this as well.


#3

Dave H. removed_email_address@domain.invalid wrote:

I “removeAllItems” because there are some in it when I create it in
InterfaceBuilder, and I just didn’t care to bother figuring out how to
place a completely empty pop-up button. :slight_smile: Also, I sometimes refresh
it, and just emptying it and refilling from scratch is easier than
modifying what’s there.

I’m sure there are other ways to do this as well.

fine, thanks, i didn’t notice the “s” in “removeAllItems”, i have to
learn how to read the classes/methods browser (AppKiDo) :wink:

because i’m using a loop :
@choixTheme.removeAllItems

@prefs.themes_list.each { |theme|
    @choixTheme.addItemWithTitle theme.label
}