[RubyCocoa] setting the items of anÊNSPopUpButton programmatically

U

Une bévue

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 :

[email protected]
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 ?
 
D

Dave Howell

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"=20
method. :)

then, what's the correct way to setup all the items of a NSPopUpButton
programmatically ?
itemArray =3D ["Unbelievable","Believable"]
@choixTheme.removeAllItems
@choixTheme.addItemsWithTitles(itemArray)
@choixTheme.selectItemWithTitle(itemArray[0])

I "removeAllItems" because there are some in it when I create it in=20
InterfaceBuilder, and I just didn't care to bother figuring out how to=20=

place a completely empty pop-up button. :) Also, I sometimes refresh=20
it, and just emptying it and refilling from scratch is easier than=20
modifying what's there.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top