-(id) init
{
if((self=[super init])) {
_targets = [[NSMutableArray alloc] init];
temp = [NSArray arrayWithObjects:@"1", @"2", @"3", @"4",nil];
tempArray = [[NSMutableArray alloc] initWithArray:temp];
resultArray = [[NSMutableArray alloc] init];
[self thelogic];
}
return self;
}
-(void)thelogic
{
int i;
int count = 4;
for (i = 0; i < 3; i ++) {
int index = arc4random() % (count - i);
[resultArray addObject:[tempArray objectAtIndex:index]];
CCSprite *target = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@.png", [tempArray objectAtIndex:index]]];
target.tag = [[NSString stringWithFormat:@"%@",[tempArray objectAtIndex:index]] integerValue];
[self addChild:target];
[_targets addObject:target];
[tempArray removeObjectAtIndex:index];
}
}
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[_targets removeAllObjects];
[self thelogic];
}
从上行代码,我得到三个不同的数字,他们提出三点精灵不同的图像时,进入这个场景,我想触摸屏,三个老精灵将被删除,并三个新的精灵会显示,但上面的代码总是崩溃,所以我该如何解决它?感谢错误索引超出范围
请发布应用程序崩溃时得到的确切错误消息... – sergio
@sergio错误消息是*** - [__ NSArrayM objectAtIndex:]:index 3 beyond bounds [0 .. 0]',谢谢 – matt