我有一个问题,弄清楚这里的错误是什么:
-(void) fireShots {
[laserBeam stop];
[laserBeam setCurrentTime:0];
[laserBeam play];
UIImageView *aShot = [[UIImageView alloc] initWithFrame:CGRectMake(actorImage.center.x, actorImage.center.y, 26, 36)];
[aShot setImage:[UIImage imageNamed:@"Laser- rød.png"]];
[allShots addObject:aShot];
if (moveAllShots == nil)
moveAllShots = [NSTimer scheduledTimerWithTimeInterval:1.0/50
target:self
selector:@selector(moveAllShots)
userInfo:nil
repeats:YES];
[actorImage.superview addSubview:aShot];
}
该方法有3个错误:预期;表达式之后(尝试通过将其插入moveallShots == nil来修复它,这显然是不正确的。 预期表达式(同一行,它是[allShots addObject:aShot]的行; 使用未声明的标识符aShot,在该方法中不可能是真实的。
真的无法想出这一个。先谢谢,
/ JBJ
答案 0 :(得分:0)
从您的示例方法fireShots
看来,您似乎从未定义过laserBeam
,allShots
和moveAllShots
。您的错误将通过在本地范围内定义变量来解决。看看如何使用变量,最好定义一个自定义类,并使用访问器将变量添加为属性来获取和设置值。
例如:由于allShots
已在头文件中定义,因此请使用属性访问该实例变量。
有关使用属性的用法,请参阅:The Objective-C Programming Language: Declared Properties
谷歌搜索也会出现一些简明的教程。