我正在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"];
...我最终得到的都是一堆未声明的标识符错误。我究竟做错了什么?
最佳答案
我需要确保您已在MyButton.h文件中定义的变量的副本,但是据我所知,从您的错误和代码中可以看到,以下行正在调用ivars:
[button1 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, 80, buttonWidth, buttonHeight)];
需要在.h文件中定义ivars centerPos,buttonWidth和buttonHeight,如果未在其中声明其中之一,则会遇到这种错误。