Mor*_*ang 1 nsmutablearray cocos2d-iphone ios nsrangeexception
我NSRangeException尝试时遇到错误removeObjectAt:0.我不知道怎么可能.
-(void)removePoints:(ccTime *)tm
{
NSLog(@"naughty %@",_naughtytoucharray);
if ([_naughtytoucharray count]>0)
{
[_naughtytoucharray removeObjectAtIndex:0];
}
}
Run Code Online (Sandbox Code Playgroud)
在日志上显示:
[4195:c07] naughty (
"{124, 98}",
"{123, 98}",
"{135, 97}",
"{124, 98}",
"{148, 94}",
"{135, 97}",
"{157, 93}",
"{148, 94}",
"{162, 92}",
"{157, 93}",
"{164, 92}",
"{162, 92}"
)
然后我收到以下错误:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 11 beyond bounds [0 .. 10]'
当我设置断点时,我看到所有对象都是 0x0

NSMutableArray被分配,初始化init和填写ccTouchesMoved
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (isSelected) {
UITouch *touch = [ touches anyObject];
CGPoint new_location = [touch locationInView: [touch view]];
new_location = [[CCDirector sharedDirector] convertToGL:new_location];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
// add my touches to the naughty touch array
[_naughtytoucharray addObject:NSStringFromCGPoint(new_location)];
[_naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
}
}
Run Code Online (Sandbox Code Playgroud)
知道为什么我不能删除数组的第一项吗?
这不是你的错误来自哪里.它抱怨的方法objectAtIndex:不是removeObjectAtIndex:,导致错误的索引是11,而不是零.
在代码中查找一个位置,假设在读取数组时,数组中至少有12个对象.只有11个,他们的索引是0到10.
| 归档时间: |
|
| 查看次数: |
477 次 |
| 最近记录: |