Cocoa forControlEvents:WHATGOESHERE

南笙酒味 提交于 2019-12-03 22:34:46

问题


In Cocoa/Objective-C if I have created a button programmatically, what do I put in for my control event?

[btnMakeChar addTarget:self action:@selector(makeChar:) forControlEvents:WHAT GOES HERE?];

In iOS you can write it like so forControlEvents: UIControlEventTouchUpInside

I can't find anything to show what I would use for just cocoa, not cocoa touch


回答1:


I'm not sure if I understand you correctly, but if you're programming a Mac,

[theHappyButton setTarget:self];
[theHappyButton setAction:@selector(doStuff)];

it is two separate lines, rather than the one combined line of code on an iPhone.

I hope that is what you were after??

To find it in the doco: choose on the 10.6 doco (not iOS) and search on "setAction:". You'll see it in NSControl Class Reference. NSButton is of course a subclass of NSControl.




回答2:


The method you're asking about does not exist in Cocoa, so nothing goes there. Cocoa controls have a single target with a single action, and either use a different addTarget:-type method for each kind of action or expect a delegate object that will handle all the events they generate.



来源:https://stackoverflow.com/questions/4685886/cocoa-forcontroleventswhatgoeshere

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!