如何将消息从目标c中的不同类传递到实例?
坚持我认为这里很简单的事情。基本上我需要将一个指向对象的指针作为参数传递到另一个类的实例方法中。换句话说:我有一个创建“事物”的类,并且我有一个我想要接收“事物”的另一个类的实例。
使用 Cocos2D 框架。 Things 是 CCSprite 的自定义子类,接收它们的实例是 CCLayer。
我想我误解了关于 ivars 或这里的属性的一些基本知识。任何正确方向的指示将不胜感激。
这是 ThingLayer 的接口,它应该接收“东西”:
@interface ThingLayer: CCLayer {
CCTextureAtlas *textureAtlas;
ThingLayer *thingLayer;
NSMutableArray *ThingsArray;
}
- moveThingtoLayer:(Thing*)athing;
@end
以下是我尝试从类外部向实例发送消息的方式:
[ThingLayer moveThingtoLayer:thing];
我意识到我在这里询问类,而不是实例......这是给我“可能不会回应...”错误。但这也不起作用(询问实例名称)...
[thingLayer moveThingtoLayer:thing];
有任何明显的答案吗?
Stuck on what I figure is simple thing here. Basically I need to pass a pointer to an object as an argument into an instance method of another class. Said differently: I have a class that creates "Things" and I have an instance of another class that I want to receive the "Things."
Working with Cocos2D frameworks. The Things are a custom subclass of CCSprite, and the instance that receives them is a CCLayer.
I figure I'm misunderstanding something basic about ivars or maybe properties here. Any pointers in the right direction would be appreciated.
Here's the interface for ThingLayer, which should receive the "thing":
@interface ThingLayer: CCLayer {
CCTextureAtlas *textureAtlas;
ThingLayer *thingLayer;
NSMutableArray *ThingsArray;
}
- moveThingtoLayer:(Thing*)athing;
@end
And here's how I'm trying to message to the instance, from outside the class:
[ThingLayer moveThingtoLayer:thing];
I realize I'm asking the class here, not the instance... which is giving me "may not respond to..." errors. But this isn't working either (asking name of instance)...
[thingLayer moveThingtoLayer:thing];
Any obvious answers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来你应该有
作为一个侧面的想法,你很可能希望在 thingLayer 中初始化一个新事物,以便该实例拥有该事物,并在调用 moveThingToLayer 后释放事物。
Looks like you should have
As a side thought, you most likely want to init a new thing in thingLayer so that instance owns the Thing, and release thing after calling moveThingToLayer.