Che*_*kie 0 iphone methods arguments selector cocos2d-iphone
我在cocos2D中使用一个调用方法并将BOOL作为参数传递的动作.
我收到警告:"传递参数3'actionWithTarget:selector:data:'使用此行生成没有强制转换的整数的指针":
id actionCharacterReaction = [CCCallFuncND actionWithTarget:self selector:@selector(characterReaction : data:) data:flipChar];
Run Code Online (Sandbox Code Playgroud)
我试过了:
id actionCharacterReaction = [CCCallFuncND actionWithTarget:self selector:@selector(characterReaction : data:) data:(BOOL)flipChar];
Run Code Online (Sandbox Code Playgroud)
我的方法看起来像这样:
-(void) characterReaction:(id)sender data:(BOOL)flipChar {
*code stuff inside*
}
Run Code Online (Sandbox Code Playgroud)
它似乎仍然很好.我对这个警告感到恼火.有任何想法吗?
你将需要你包裹flipChar在NSNumber它正确传递作为参考.使用选择器时,无法直接传递基本类型.
id actionCharacterReaction = [CCCallFuncND actionWithTarget:self
selector:@selector(characterReaction : data:)
data:[[NSNumber numberWithBool:flipChar] retain]];
...
-(void) characterReaction:(id)sender data:(NSNumber*)flipChar {
BOOL fc = [flipChar boolValue];
*code stuff inside*
[flipChar release]; //Retained in call to CCCallFuncND
}
Run Code Online (Sandbox Code Playgroud)
编辑:在简要查看文档后,它看起来需要一个void*.既然void*可以是任何对象,而不仅仅是Objective-C对象,那么您可能需要手动保留和释放该数字.上面的代码已更新.