Call an IBAction from different IBAction

I have created an IBAction ClearAllFields_(sender) that is hooked up to a button. I’d like to call that IBAction from the applicationWillFinishLaunching_(aNotification) IBAction. What is the correct syntax?

Thanks in advance,
Brad Bumgarner


You can put anything in the the braces really, assuming you don’t use sender in your action handler, but me is the sender in this case.

Also, you shouldn’t begin handler names with an uppercase letter; they are generally reserved for classes.

Once again I’ve answered my own question! :smiley: It seems that all I have to do is to post the question here and THEN I find the answer! :lol:

The answer to this question is when calling the ClearAllFields_ from within another IBAction is to put “me” (without the quotes) in the parentheses.

I wonder how many more of my questions I’ll be able to answer AFTER posting them here?

Brad Bumgarner

Strange this means that when calling an handler the passed arguments aren’t converted to cocoa objects? For actions it is in Objective-C - (IBAction) actionName:(id) sender where IBAction is actually a void so it means your handler don’t return anything and (id) means that the passed argument can be any type of object. “me” will be converted to an NSString, which is an object, and therefore can be passed as an argument to an action without problem. So an sender as string shouldn’t be any problem or am I missing something here?

Brad, you can also pass in null or missing value when you call a handler from within the code. That is, if you don’t need to pass anything into the method.

@DJ: I wouldn’t think there would be a problem using a string as the sender. In ASOC, you could pass an Applescript string into a function. There are the Cocoa/ObjC methods that we can call, and then we could make our own functions, called from UI elements also. Maybe we can pass Applescript objects to our own methods, but then when we use an ObjC method, the passed in variable gets converted to it’s ObjC form, or if not gives us errors and we have to coerce it.
I don’t think “me” would be converted to a string. I think it’s a special known constant (soft of like “self” in ObjC). Maybe Shane can clarify.

@smg: Precisely, that’s what I also trying to say. Don’t forget that missing value is also an object. Well I interpreted brad’s post as that you must pass a me as argument to the action. Also you interpreted my “me” as me but I was talking about a string containing me as an example to let the readers know that it doesn’t matter what kind of object you’re sending as long as it is an object.

Using missing value is probably not a good idea because if your handler does later do something to sender, the problem will be easier to track down – if sender is missing value, there will be no immediate error.

Thanks for the info Shane. We must have posted at about the same time. Regarding the uppercase first letter…I know, I have old Applescript Studio habits to break. I started learning Obj-C a couple of years ago and then got away from programming altogether until just very recently.

Brad Bumgarner