Set Button selector (on click event) at runtime ? (Cocoa : Mac Project)

前端 未结 2 1718
眼角桃花
眼角桃花 2021-01-24 23:50

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 <         


        
2条回答
  •  时光说笑
    2021-01-25 00:19

    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.

提交回复
热议问题