2012-01-28 116 views
0

我有一个问题搞清楚究竟什么是错在这里:代码中的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 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

注 - 我只是解决了NSTimer moveAllShots的问题,但与[allShots addObject:aShot]一致的问题;仍然存在 - 我相信NSMutableArray是分配的,所以我不知道这里有什么错。 – Seerex 2012-01-28 17:19:49

+1

allShots定义在哪里? – Nick 2012-01-28 17:19:56

+0

NSMutableArray * allShots;在该类 – Seerex 2012-01-28 17:24:23

回答

0

从您的样本方法fireShots它看起来像你从未定义过laserBeam,allShotsmoveAllShots。您的错误将通过定义本地范围内的变量。看看你如何使用变量,你最好定义一个自定义的类,并使用访问器来添加变量作为属性来获取和设置值。

例如:由于allShots是在您的头文件中定义的,请使用属性来访问该实例变量。

有关使用性质使用,请参阅:The Objective-C Programming Language: Declared Properties

谷歌搜索也将开启了一些简明教程。