[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[RubyCocoa] setting the items of anÊNSPopUpButton programmatically

pere.noel

2/4/2006 9:22:00 AM

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 ?


--
une bévue
2 Answers

Dave Howell

2/10/2006 10:38:00 PM

0


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. :)


> 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. :) 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.



pere.noel

2/11/2006 9:47:00 AM

0

Dave Howell <groups@grandfenwick.net> 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. :) 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) ;-)

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

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

--
une bévue