Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use void instead IBAction as return type of method

I'm studying ObjC and iOS development. Every components that I use in my apps are created programmatically (views, button, labels, etc).

Here is my code

...
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.btn addTarget:self 
                  action:@selector(someAction:) 
        forControlEvents:UIControlEventTouchDown];
....


-(void)someAction
{
 logic
}

I notice that I can use void instead of IBAction as return type of selector. Is this the correct approach ? Could there be any pitfalls ?

like image 265
objlv Avatar asked Feb 04 '12 18:02

objlv


1 Answers

Using IBAction tells Xcode that you want the method to be available as an action method in Interface Builder. That's the only effect. Otherwise it is identical to void. In fact in UINibDeclarations.h you will find this:

#define IBAction void

Using IBAction is a good idea even if you don't use nib files, because it is a signal to the reader (you or a coworker) that you intended to use the method as the action of a UI control.

like image 77
rob mayoff Avatar answered Oct 29 '22 02:10

rob mayoff