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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With