虽然有 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 异常。
有人可以帮我吗?
非常感谢基督徒