向数组添加项目似乎不起作用

Chr*_*ris 0 iphone objective-c

我写了一个函数,将一个球添加到一个数组但是当我检查它没有增加的数量时,请有人建议.

NSMutableArray *_otherBalls;


-(void)addBall{
    CCSprite *target = [CCSprite spriteWithFile:@"redbouncyball.gif" rect:CGRectMake(0, 0, 27, 40)]; 

    [self addChild:target];

    //add to our array
    [_otherBalls addObject:target];

    NSLog(@"Added ball : %@",[_otherBalls count]);
}
Run Code Online (Sandbox Code Playgroud)

日志出来了

添加球:( null)

Cyp*_*ian 5

从您的代码中可以看出您从未初始化过该阵列的接缝.所以它不能存储任何东西.除非你在init中做过,但那很难猜到.