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
IBActiontells 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 tovoid. In fact inUINibDeclarations.hyou will find this:Using
IBActionis 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.