【发布时间】:2012-05-21 17:07:01
【问题描述】:
我有这个:
//Node.h
@interface Node: CCSprite{
BOOL wasTouched;
}
-(BOOL)getTouched;
// some other methods
//Node.m
-(BOOL)getTouched{
return wasTouched;
}
-(id)init{
wasTouched=NO;
}
//wasTouched changes in the other methods..when they are called (no problem here)
//Game.m
//i make an array of nodes and do some stuff
-(void)someMethod{
for (Node *node in arrayOfNodes){
if ([node getTouched]) { //here it crashes
//code
}}}
它崩溃并显示消息-[CCSprite getTouched]: unrecognized selector sent to instance 0x236dd0
问题是:为什么?!
【问题讨论】:
-
您如何收到
arrayOfNodes,您能否确认其中确实只包含Node对象而没有CCSprite? -
我在 Game 的 init 方法中创建了一个随机的节点数组,并且我已经检查过了,其他自定义方法可以工作..只有这个不行。我正在尝试重写我的代码来解决这个问题