我在找出这里到底出了什么问题时遇到了问题:
-(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个错误: Expected;after expression (尝试通过在moveallShots == nil处插入它来修复它,这显然是不正确的。期望的表达式(同一行,它是allShots addObject:aShot的行;使用未声明的标识符aShot,这也不可能是真的,因为它是在该方法中创建的。
真的搞不懂这件事。先谢谢你,
/JBJ
发布于 2012-01-29 01:41:20
从您的示例方法fireShots看,您似乎从未定义过laserBeam、allShots和moveAllShots。您的错误将通过在局部作用域中定义变量来解决。看看您是如何尝试使用变量的,您最好定义一个自定义类并添加变量作为属性,使用访问器来获取和设置值。
例如:由于allShots是在您的头文件中定义的,因此使用一个属性来访问该实例变量。
有关使用属性的用法,请参阅:The Objective-C Programming Language: Declared Properties
谷歌搜索也会出现一些简明的教程。
https://stackoverflow.com/questions/9047191
复制相似问题