3

我正在用 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"];

...我最终得到的只是一堆未声明的标识符错误。我究竟做错了什么?

4

1 回答 1

2

我需要查看您在 MyButton.h 文件中定义的变量的副本以确定,但据我所知,从您的错误和您的代码中可以看出,以下行正在调用 ivars:

[button1 ellipse:CGRectMake(centerPos.x - buttonWidth/2.0f, 80, buttonWidth, buttonHeight)];

需要在您的 .h 文件中定义 ivars centerPos、buttonWidth 和 buttonHeight,如果其中一个没有被声明,那么您将遇到这种错误。

于 2012-04-20T21:59:46.390 回答