How to call "removeAllItems" for a NSComboBox?

My application has a user configurable list of items. I can populate a NSComboBox in my interface with the list of these items no problem.

I need to make this list user configurable, however, which means when a user changes the list, the combo box needs to be cleared, and the new list re-added.

I have tried a bunch of things:

    -- Set up the genres
    myComboBox's removeAllItems_()
    myComboBox's addItemsWithObjectValues_(myList)

The “addItemsWithObjectValues” works great, but “removeAllItems” is not working, I get a “unrecognized selector sent to instance”.

Is there a different syntax for calling a method without any parameters?

Your using an underscore in the removeAllItems method call, you only use the underscore if your passing parameters or arguments to the method, which your not needing to in this case, so use the method as shown in the example below.


myComboBox's removeAllItems()

Regards Mark

Geeze thanks. Works great now.

That’s some odd syntax, I assumed the “_” was how applescript “knows” that you are calling a method in Obj-C. I guess I need to read more!

No you only need to use the the"_" underscore character when supplying parameters to the method, if the method does actualy require certain params, if the Cocoa framework class does not require any params for a particular method, then dont use one, but do use the pair of empty braces, for example.


-- The NSComboBox removeItemAtIndex: method requires a Integer perameter so use the underscore like this.

myComboBox's removeItemAtIndex_(myInteger)

-- The insertItemWithObjectValue:atIndex: method requires two params, so use two underscore characters like this.

myComboBox's insertItemWithObjectValue_atIndex_(myObject, myInteger)

-- and if the method does not require any params, then just use the empty braces, like this

myClassObject's methodeName()

-- And if your using Applescript version 2.3, targeting Mavericks or newer, then consider using the new interleaved
-- syntax that is the same as Objective-C, like this.

myComboBox's insertItemWithObjectValue:myObject atIndex:myInteger

I hope this makes things clearer.

Regards Mark