Any idea how to set button selector at runtime (on click event) for mac (Not IOS)
I have a view controller with a button declared as outlet :
#import <
You shall look at the NSControl class reference (from which NSButton inherits) for two separate methods setTarget:
and setAction:
.
You can do something like this in your code:
[MyBtn setTarget:self];
[MyBtn setAction:@selector(doStuff)];
take a look also at this answer.
those two methods are what you are looking for.
================
[myButton setSelector:@selector(myButtonClickEvent:)];
-(void) myButtonClickEvent:(id) sender{
NSLog(@"button:%@ be clicked. :)", sender);
}