我喜欢这个错误here,但得出的结论是由于数组为空而发生错误。然而,我的数组不是空的。
-(void)setNumberInTippfield:(NSNumber *)aNumber{
NSNumber *index = [self.ticket.currentSlip intValue]-1;
NSLog(@"index: %i",index);//prints 0, expected
Slip *slip = [self.slipArray objectAtIndex:index];
NSNumber *number = [NSNumber numberWithInt:[aNumber intValue]-1 ];
NSLog(@"number: %@",number);//prints out number, e.g. 25, as expected
NSMutableArray *tNumberArray = [[NSMutableArray alloc] init];
tNumberArray= [NSMutableArray arrayWithArray:slip.numberArray];
//after this line, debugger tells me the array has 49 objects, as expected
[[tNumberArray objectAtIndex:number] setSelected:YES];//this line throws exception
//this line seems to get executed 3 times, as I can see from the breakpoints
}
之后它抛出一个异常:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -
[__NSArrayM objectAtIndex:]: index 517431040 beyond bounds [0 .. 48]'
我认为它number
包含一个地址而不是一个值,但 NSLog 告诉我正确的值。关于那个有任何提示吗?提前非常感谢。