You have to create actual objects of that class:

MyClass * obj = [[MyClass alloc] init];

then send your '-' messages to that object:

[obj myAction:arg];

You might want to read up some more on object oriented programming so you know the difference between an object and its class. A class is basically a template explaining how every object that's made from it behaves.


On Apr 11, 2008, at 6:31 PM, Kevin Ferguson wrote:

reetings!

This is a rather odd (and I'm sure simple) question, but I cannot seem to find a suitable explanation anywhere I look.

So, my code initializes a menu with an action "myAction:", whose target is "myClass".

Now, I've noticed through trial and error that the only way to get my method to respond to the menu is to mark the method with a + as opposed to a -.
This means my method declaration is now +(void)myAction:(id)sender { }

So, this much I have working. Now, within that method, I programmatically create a panel and a few text boxes, along with a button with the action "doStuff" whose target is also "myClass". At the end of the method, I tell the panel to display, and everything, including the button, works fine. (An NSlog put in the doStuff: method activates) I noticed that the method that my button calls also must have the + to do anything.

However, the moment I try to access any of my objects (the button, or text boxes) that I created in the myAction: method, I get a warning saying that I'm accessing an instance variable from a class method, even though it is declared in the class's header file. As such, I can't really interact with it.

Now, I'm entirely self-taught in Cocoa, so this may be something more obvious than I think. Is there a reason for this occurrence? I assume it's got something to do with the +, but not knowing what the + means, or why my method must be a + to work, I can't really determine what to do. Can this be explained at all, or can anyone point me to a place that would explain it?

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to