开发者

NOOB Problems with getting results from code (more specificly with NSComboBox)

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 [midiMo开发者_Go百科delContents 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜