Iphone 代码中Xcode中的奇怪错误?

Iphone 代码中Xcode中的奇怪错误?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我很难弄清楚这里到底出了什么问题: -(void) fireShots { [laserBeam stop]; [laserBeam setCurrentTime:0]; [laserBeam play]; UIImageView *aShot = [[UIImageView alloc] initWithFrame:CGRectMake(actorImage.center.x, actorImage.center.y, 26, 36)]; [aShot

我很难弄清楚这里到底出了什么问题:

-(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个错误:预期错误;after表达式(尝试通过在moveallShots==nil处插入它来修复它,这显然是不正确的。 预期表达式(同一行,表示[allShots addObject:aShot]的行); 使用未声明的标识符aShot,这也不可能是真的,因为它是在该方法中创建的

我真的搞不懂这个,谢谢你


/JBJ

从您的示例方法
fireShots
来看,您似乎从未定义过
laserBeam
allShots
moveAllShots
。您的错误将通过在局部范围内定义变量来解决。查看您如何尝试使用这些变量,您最好定义自定义类and使用访问器将变量添加为属性以获取和设置值

例如:由于头文件中定义了
allShots
,因此请使用属性访问该实例变量

有关使用属性的信息,请参见:


谷歌搜索也会出现一些简明的教程。

注意-我刚刚解决了NSTimer moveAllShots的问题,但是[allShots addObject:aShot]行中的问题;仍然存在-我确信NSMutableArray已分配,因此我不知道这里出了什么问题。NSMutableArray*allShots;在该类的.h文件中,您忘记了分号或}。请正确检查代码。您还存在“aShot”内存泄漏内存泄漏?在哪里?aShot被添加到allShots数组中,以便以后可以删除?如何删除那是个漏洞吗?