我有touchesBegan方法,只要我触摸Circle类的对象就会调用它。 (UIView的子类)
所以,我想要的是,当我触摸一个圆圈时,它被放置在一个NSMutableArray中,被设置为隐藏,它可以工作并从数组中移除。那时,编译器抛出了这个错误:
2014-12-23 14:07:09.094 Tap them all[986:39194] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105edcf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001057ccbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105dc7f33 -[__NSArrayM objectAtIndex:] + 227
3 Tap them all 0x0000000104f44fc1 -[ViewController moveCircles] + 81
4 Foundation 0x00000001053862b4 __NSFireTimer + 83
5 CoreFoundation 0x0000000105e44f64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
6 CoreFoundation 0x0000000105e44b25 __CFRunLoopDoTimer + 1045
7 CoreFoundation 0x0000000105e07e5d __CFRunLoopRun + 1901
8 CoreFoundation 0x0000000105e07486 CFRunLoopRunSpecific + 470
9 GraphicsServices 0x0000000108db79f0 GSEventRunModal + 161
10 UIKit 0x00000001062c9420 UIApplicationMain + 1282
11 Tap them all 0x0000000104f45e53 main + 115
12 libdyld.dylib 0x0000000109a9a145 start + 1
13 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
为什么会这样? 提前谢谢!
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
int k = 0;
while (k < array.count) {
if ([touch view] == array[k]) {
[array[k] setHidden:YES];
[array removeObjectAtIndex:k];
break;
}
k++;
}
}