Use colon : or not with selectors

回眸只為那壹抹淺笑 提交于 2019-12-05 14:40:23

The colon is needed after the method's name if and only if the method takes an argument.

No function parameters:

-(void)addAction {}

// Use ...@selector(addAction)...

Has parameter:

-(void)addAction:(id)info {}

// Use ...@selector(addAction:)...

In certain cases, the number of colons can determine arguments. For example, if you pass in an action method with one colon, it'll send the sender as the first argument. If you pass in a selector with two colons, you'll get the event as well. No colon means, obviously, no arguments.

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