使用冒号:或不与选择器一起使用 [英] Use colon : or not with selectors

查看:154
本文介绍了使用冒号:或不与选择器一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道:写没有冒号@selector(mySelector)或没有冒号@selector(mySelector:)的选择器名称有什么区别?

I was wondering: what's the difference between writing a selector name with no colon @selector(mySelector), or @selector(mySelector:) with the colon?

如:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWith... 
                                                       target:self
                                                       action:@selector(addAction:)];

没有冒号我找不到另一个例子,但是我很确定我已经看过其中一些.

I can't find another example without the colon, but I'm quite sure I have already seen some of them.

推荐答案

方法名称为且仅当使用参数时,才需要冒号.

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

没有功能参数:

-(void)addAction {}

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

有参数:

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

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

这篇关于使用冒号:或不与选择器一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆