工作时间表如何使用选择器和参数?

时间:2013-03-08 15:39:41

标签: objective-c cocos2d-iphone

Xcode在YES

之前期待')'

[_creep scheduleOnce:@selector(removeFromParentAndCleanup:YES) delay:2.0f];

对不起,如果它看起来很基本......我刚刚开始了ObjectiveC。

1 个答案:

答案 0 :(得分:2)

因为Cocos API将您限制为一个带有1个参数的选择器(ccTime),所以编写自己的方法将给定的参数传递给正确的函数:

-(void)doneWithSomething {
    [self scheduleOnce:@selector(removeAndCleanup:) delay:2.0f];
}

-(void)removeAndCleanup:(ccTime)delta {
    [ _creep removeFromParentAndCleanup:YES];
}

你不能在@selector()指令中传递参数,因为它直接与vTable中的条目(对于常用方法)或ObjC sel缓存中的条目相关联,因此编译器认为您正在尝试调用一种名为-removeFromParentAndCleanup:YES

的不可能名称的方法