Re: NSPopUpMenuItem question
Re: NSPopUpMenuItem question
- Subject: Re: NSPopUpMenuItem question
- From: j o a r <email@hidden>
- Date: Sun, 16 Jun 2002 00:47:35 +0200
Hi Matthew,
On Saturday, Jun 15, 2002, at 21:20 Europe/Stockholm, Matthew Kelley wrote:
I am new to objective-c programming and cocoa, and I was wonder what you would call a NSPopUpMenuItem.
What is a "NSPopUpMenuItem", where did you get that from? You can't just make up class names or data types you know... ;)
- (IBAction)enterOp:(id)sender
{
if (yFlag) {
switch (operation) {
case centimetersToMeters:
X = .01 * X;
break;
}
}
Y = X;
yFlag = YES;
operation = [ [sender selectedPopUpMenuItem] tag];
enterFlag = YES;
[self displayX];
}
Your method "enterOp:"gets a parameter called "sender" of type "id". "id" means that it could be any type of object, but I assume that you have hooked up this method to be triggered by the action of a NSPopUpButton or a NSMenuItem? From the error message I take it that it is a NSMenuItem, but if you are unsure you can always find out like this.
NSLog(@"What type of class is sender: %@", [sender class]);
Later on in the code you call a method in the "sender" object - "selectedPopUpMenuItem". Again, where did you get that message name? You need to either look up the names in the documentation, or ask the object if it responds to a particular method before calling it.
From your code I see that you are looking for the tag of the menu item, looking in the documentation for NSMenuItem we find that such a method exists:
- (int) tag
All right - provided that the rest of your code does what it should - you should then replace this line:
operation = [ [sender selectedPopUpMenuItem] tag];
with something like this:
operation = [sender tag];
Regards,
j o a r
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.