在类方法中调用父类给了我“匹配方法签名”警告
我有一个类,其中添加了两个类 A 和 B。在 A 类的方法中,我尝试调用 B 类方法
假设父类是 debugZoneScene,debugZoneLayer 是 A 类,tetraCounter 是 B 类。
这是 debugZoneLayer(A 类)中的一个方法:
-(void) getHeroVel {
DebugZoneScene *debugZoneScene = (DebugZoneScene*)self.parent;
[debugZoneScene.tetraCounter setTetras];
}
它调用该方法,但我收到警告:
'-[DebugZoneLayer getHeroVel]': “CCNode”可能不会响应“-setTetras”(没有匹配方法签名的消息将被假定返回“id”并接受“...”作为参数。)
我尝试过谷歌搜索这个,但我真的找不到任何与我的问题完全相关的东西。我正在使用 Cocos2D,但我认为这个问题与此没有任何直接关系,并且仍然可以通过 Objective C 知识来解决。有什么想法吗?
I have a class that has two classes A and B added to it. In a method in class A, I am trying to call a class B method
Let's assume that the parent class is debugZoneScene, debugZoneLayer is class A and tetraCounter is class B.
Here is a method from debugZoneLayer (class A):
-(void) getHeroVel {
DebugZoneScene *debugZoneScene = (DebugZoneScene*)self.parent;
[debugZoneScene.tetraCounter setTetras];
}
It calls the method, but I get the warning:
'-[DebugZoneLayer getHeroVel]':
'CCNode' may not respond to '-setTetras' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)
I've tried Googling this, but I couldn't really find anything that related exactly to my problem. I am using Cocos2D, but I think this problem doesn't have anything to do directly with that, and can still be resolved having knowledge in Objective C. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编译器告诉您,它认为
debugZoneScene.tetraCounter
是CCNode
类型的对象,而不是您的ClassB
类型的对象。检查tetraCounter
是如何在DebugZoneScene
中声明和分配的。您可以通过强制转换使警告消失:
这告诉编译器您不关心它的想法,并且您确定该对象是
ClassB
。然而,这并不能解决实际问题。The compiler is telling you that it thinks that
debugZoneScene.tetraCounter
is an object of typeCCNode
, not whatever yourClassB
is. Check howtetraCounter
is declared and allocated inDebugZoneScene
.You can make the warning go away by casting:
this tells the compiler that you don't care what it thinks and you're sure that the object is
ClassB
. This doesn't solve the actual problem, however.您的伪代码确实适合您...如果没有有关 setTetras 签名的更多详细信息,将很难猜测您的代码中出了什么问题 ^^
无论如何,您是否 #import TatraCounter 类声明的标头,以便您所在的文件编写此代码知道 TetraCounter 对象的可用方法(及其签名)吗?
Your pseudo really fits you... without more details about the signature of setTetras, it will be quite difficult to guess what is wrong in your code ^^
Anyway did you #import the header for TatraCounter class declaration, so that the file where you wrote this code knows about the methods available (and their signature) for the TetraCounter objects?