我在C4制作一个程序,它由三个独立的按钮组成,按下时会改变它们的形状。当我为每个按钮创建一堆方法时:
@implementation MyButton
-(void)methodA {
C4Log(@"methodA");
[button1 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, 80, buttonWidth, buttonHeight)];
}
-(void)methodB {
C4Log(@"methodB");
[button2 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, centerPos.y - buttonHeight/2.0f, buttonWidth, buttonHeight)];
}
-(void)methodC{
C4Log(@"methodC");
[button3 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, canvasHeight - 280, buttonWidth, buttonHeight)];
}
@end
...然后在画布中调用它们......
[button1 listenFor:@"touchesBegan" fromObject:button1 andRunMethod:@"methodA"];
[button2 listenFor:@"touchesBegan" fromObject:button2 andRunMethod:@"methodB"];
[button3 listenFor:@"touchesBegan" fromObject:button3 andRunMethod:@"methodC"];
...我最终得到的是一堆未声明的标识符错误。我做错了什么?
答案 0 :(得分:2)
我需要查看您在MyButton.h文件中定义的变量的副本以确定,但据我从您的错误和您的代码中可以看出,以下行调用了ivars:
[button1 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, 80, buttonWidth, buttonHeight)];
需要在.h文件中定义ivars centerPos,buttonWidth和buttonHeight,如果其中一个未被声明,那么您将遇到此类错误。