Forum: Ruby setting the items of anÃ?NSPopUpButton programmatically

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-02-04 11:25
(Received via mailing list)
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 ?
Dave H. (Guest)
on 2006-02-11 00:37
(Received via mailing list)
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.
unknown (Guest)
on 2006-02-11 11:48
(Received via mailing list)
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. :) 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
    }
This topic is locked and can not be replied to.