OOP の経験はありますが、Objective-C の初心者です。次のコードがあります。
// header files have been imported before this statement...
CCSprite *treeObstacle;
NSMutableArray *treeObstacles;
@implementation HelloWorldLayer {
}
-(id) init
{
// create and initialize our seeker sprite, and add it to this layer
treeObstacles = [NSMutableArray arrayWithObjects: nil];
for (int i=0; i<5; i++) {
treeObstacle = [CCSprite spriteWithFile: @"Icon.png"];
treeObstacle.position = ccp( 450-i*20, 100+i*20 );
[self addChild:treeObstacle];
[treeObstacles addObject: treeObstacle];
}
NSLog (@"Number of elements in array = %i", [treeObstacles count]);
return self;
}
- (void) mymethod:(int)i {
NSLog (@"Number of elements in array = %i", [treeObstacles count]);
}
@end
最初の NSLog() ステートメントは、「配列の要素数 = 5」を返します。問題は、(treeObstacles はファイル スコープ変数ですが) メソッド "mymethod" を呼び出すと、EXC_BAD_ACCESS 例外が発生することです。
誰でも私を助けてもらえますか?
どうもありがとうクリスチャン