# What's an IBAction?



## rharder (Jul 25, 2001)

A method that's called as an action from Interface Builder has the signature 
_- (IBAction)actionName: (id)sender_. 

What's an IBAction? Is it an object (an _id_)? A constant?

I don't return anything from these methods, but could I?

-Rob


----------



## endian (Jul 25, 2001)

> I don't return anything from these methods, but could I?



Nope, IBAction is defined as void. It's just there so IB can parse your header when you drag it into IB.


----------



## rharder (Jul 25, 2001)

If I have an IBAction method, will its return value be nil if I do something like this:
	
	



```
id obj = [self buttonPressed:self];
```
-Rob


----------



## endian (Jul 25, 2001)

i doubt that'd even compile.. it'll probably say something like 'assigning void value should be ignored.' *void* isn't nil, it's just nothing.

not sure what you're trying to do, but you can differentiate between multiple buttons calling the same action with the tag instance variable - give each button a unique tag value, then do something like

```
-(IBAction)buttonPressed:(id)sender
{
	switch ( [sender tag] )
	{
	case 1:
	//blah blah blah
	break;

	case 2:
	//blah blah etc.
	break;
	}
}
```

You could obviously call your own methods and return whatever you want from there.


----------



## rharder (Jul 26, 2001)

I was wondering if I could use an IBAction method by invoking a selector at run-time which is a trick I'm trying with the ThreadWorker class (http://iharder.net/macosx/threadworker).

I'm away from any NS*-capable compiler for a while, so I can't experiment.

-Rob


----------



## endian (Jul 26, 2001)

you can invoke it at runtime, you just can't return anything.

e.g. [window makeKeyAndOrderFront:nil];


----------



## rharder (Jul 27, 2001)

So I finally got back to my OS X box, and yes, you can set a variable equal to the return value of a method that returns void (or at least, IBAction). Essentially, you're setting the variable to nil. That's not a problem.

-Rob


----------

