views:

12

answers:

1

I know that this is probably a simple question but here is what I'm racking my brain to figure this out:

I know that this:

- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index {
return [midiModelContents objectAtIndex:index];

}

will return the item at the index provided. My question is, what code do I need to use to call this routine?

I've tried something like this:

NSString *curData =(comboBox: midiModel objectValueForItemAtIndex:0);

but I get a "error: 'comboBox' undeclared"

Can anyone help me with the concept that I'm messing up?

Thanks a bunch

Loren

+1  A: 

First, you might want to read the Objective-C Programming Language to learn the correct syntax for sending messages to objects, including yourself.

You get a nonsense error message because you have written (what is in Objective-C) nonsense code. A valid Objective-C message expression would compile and run successfully, but I don't think it would do what you're expecting it to.

You see (and this is the second thing), comboBox:objectValueForItemAtIndex: is not ordinarily a message you send to yourself. The combo box sends that message to you when you are its data source. Data sources are a variation on the delegate pattern that is among the things described in detail in the Cocoa Fundamentals Guide.

(You can send the message to yourself, and it may even make sense to do this if you deliberately want to go through the same object-value-retrieval path the combo box does, but this is not what you need to do to make a combo box work.)

Both the Language document and the Cocoa Fundamentals document are essential reading for every Cocoa programmer, along with the Memory Management Guide for Cocoa. You should read all three documents from start to finish.

The solution to your immediate problem is for the object that responds to comboBox:objectValueForItemAtIndex: to be the data source of the combo box. You will probably hook this up in IB, in the same nib where you created the combo box.

If none of that makes any sense, then all I can suggest to you is, again, to read those documents. They will explain everything.

If you really did simply mean to ask yourself for the object value the same way the combo box does (i.e., you have the combo box working already and intend to get the object value the same way for some other purpose), then you still need to read the Objective-C Programming Language document to learn the correct syntax to send yourself that message.

Peter Hosey
Thanks for the point in the right direction. I have started the reading that you have suggested. I also have found the code that I was looking for from your explanation of how the combobox sends out information.
Loren Zimmer