Tried this but only works for UIButton:
[btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
@wp42 It does work today.
A nifty way of doing this in objective-C is adding a category to UIBarButtonItem class:
.h file
#import
@interface UIBarButtonItem (addons)
-(void)addTarget:(id)target andAction:(SEL)action;
@end
.m file
#import "UIBarButtonItem+addons.h"
@implementation UIBarButtonItem (addons)
-(void)addTarget:(id)target andAction:(SEL)action{
[self setTarget:target];
[self setAction:action];
}
@end
In practice:
[myBtn addTarget:self andAction:@selector(myFunction:)];