使用冒号:或不使用选择器

Pau*_*aul 4 objective-c selector colon

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

如:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWith... 
                                                       target:self
                                                       action:@selector(addAction:)];
Run Code Online (Sandbox Code Playgroud)

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

Eva*_*ski 13

当且仅当方法采用参数时,才需要在方法名称后面添加冒号.

没有功能参数:

-(void)addAction {}

// Use ...@selector(addAction)...
Run Code Online (Sandbox Code Playgroud)

有参数:

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

// Use ...@selector(addAction:)...
Run Code Online (Sandbox Code Playgroud)