Iphone 由于未捕获异常而终止应用程序';NSGenericeException
我正在使用UIImagePickerController从iphone库加载保存的照片。 但是当我向上或向下滚动图像时,我的应用程序崩溃了 我发现以下错误:Iphone 由于未捕获异常而终止应用程序';NSGenericeException,iphone,Iphone,我正在使用UIImagePickerController从iphone库加载保存的照片。 但是当我向上或向下滚动图像时,我的应用程序崩溃了 我发现以下错误: 2011-04-21 14:26:33.357 Exchange[72452:5803] Running conversion tracker in a background thread. 2011-04-21 14:26:40.449 Exchange[72452:207] upload from gallery event here
2011-04-21 14:26:33.357 Exchange[72452:5803] Running conversion tracker in a background thread.
2011-04-21 14:26:40.449 Exchange[72452:207] upload from gallery event here
2011-04-21 14:26:42.277 Exchange[72452:207] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x6dc35a0> was mutated while being enumerated.(
"<PLImageTableSegment: 0x6937f80>",
"<null>",
"<null>",
"<null>",
"<null>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>",
"<PLImageTableSegment: 0x6937f80>"
)'
*** Call stack at first throw:
(
0 CoreFoundation 0x015645a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x016b8313 objc_exception_throw + 44
2 CoreFoundation 0x01564069 __NSFastEnumerationMutationHandler + 377
3 CoreFoundation 0x0155d838 -[__NSArrayM dealloc] + 152
4 PhotoLibrary 0x0608d696 +[PLImageTable releaseSegmentCache] + 37
5 PhotoLibrary 0x0606cf5a -[PLPhotoLibrary dealloc] + 183
6 CoreFoundation 0x0147b04c CFRelease + 92
7 CoreFoundation 0x014a018d _CFAutoreleasePoolPop + 237
8 Foundation 0x000e33eb -[NSAutoreleasePool release] + 167
9 UIKit 0x003943ee _UIApplicationHandleEvent + 8792
10 GraphicsServices 0x01d9c992 PurpleEventCallback + 1550
11 CoreFoundation 0x01545944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
12 CoreFoundation 0x014a5cf7 __CFRunLoopDoSource1 + 215
13 CoreFoundation 0x014a2f83 __CFRunLoopRun + 979
14 CoreFoundation 0x014a2840 CFRunLoopRunSpecific + 208
15 CoreFoundation 0x014a2761 CFRunLoopRunInMode + 97
16 GraphicsServices 0x01d9b1c4 GSEventRunModal + 217
17 GraphicsServices 0x01d9b289 GSEventRun + 115
18 UIKit 0x00397c93 UIApplicationMain + 1160
19 ArmaniExchange 0x000022a4 main + 102
20 ArmaniExchange 0x00002235 start + 53
21 ??? 0x00000001 0x0 + 1
)
terminate c
2011-04-21 14:26:33.357 Exchange[72452:5803]在后台线程中运行转换跟踪器。
2011-04-21 14:26:40.449交换[72452:207]从画廊活动上传
2011-04-21 14:26:42.277 Exchange[72452:207]***由于未捕获的异常“NSGenericeException”而终止应用程序,原因:***集合在枚举时发生了变异(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
)'
***第一次抛出时调用堆栈:
(
0 CoreFoundation 0x015645a9例外预处理+185
1 libobjc.A.dylib 0x016b8313 objc_异常_抛出+44
2 CoreFoundation 0x01564069\uuu NSFastEnumerationMutationHandler+377
3核心基金会0x0155d838-[uuu NSArrayM dealloc]+152
4照片库0x0608d696+[PLImageTable releaseSegmentCache]+37
5照片库0x0606cf5a-[PLPhotoLibrary解除锁定]+183
6芯基础0x0147b04c CFRelease+92
7 CoreFoundation 0x014a018d\u CFAutoreleasePoolPop+237
8基金会0x000 0E33 EB - [ NSAutoReleSeCelp释放] + 167
9 UIKit 0x003943ee _UIApplicationHandleEvent+8792
10个图形服务0x01d9c992 PurpleEventCallback+1550
11 CoreFoundation 0x01545944 \uuuu CFRUNLOOP \u正在调用\u OUT \u以执行\u函数\uuu+52
12 CoreFoundation 0x014a5cf7__CFRunLoopDoSource1+215
13 CoreFoundation 0x014a2f83 _ucfrunlooprun+979
14 CoreFoundation 0x014a2840 CFRunLoopRunSpecific+208
15 CoreFoundation 0x014a2761 CFRunLoopRunInMode+97
16图形服务0x01d9b1c4 GSEventRunModal+217
17图形服务0x01d9b289 GSEventRun+115
18 UIKit 0x00397c93 UIApplicationMain+1160
19 ArmaniExchange 0x000022a4干管+102
20 ArmaniExchange 0x00002235启动+53
21°?0x00000001 0x0+1
)
终止c
在抛出“NSException”实例后调用
提前感谢。寻找一个for循环,该循环可以在迭代过程中添加或删除对象。可能在
[PLImageTable releaseSegmentCache]
中。例如:
for (NSString *string in stringsArray) {
[stringsArray removeObject:string];
}
NSMutableArray *objectsToDelete = [NSMutableArray array];
for (id object in array) {
// do something with object
if ([object meetsCondition:@"Foo"]) {
[objectsToDelete addObject:object];
}
}
[array removeObjectsInArray:objectsToDelete];
打开
PLImageTable
的releasemsectioncache
方法。您会发现类似以下代码:
for (id object in array) {
// do something with object
if ([object meetsCondition:@"Foo"]) {
[array removeObject:object];
}
}
但在枚举数组时,不允许更改数组。所以你必须找到另一个解决方案。您可以将所有应该删除的对象保存到另一个数组中,然后在完成枚举时删除所有这些对象。例如:
for (NSString *string in stringsArray) {
[stringsArray removeObject:string];
}
NSMutableArray *objectsToDelete = [NSMutableArray array];
for (id object in array) {
// do something with object
if ([object meetsCondition:@"Foo"]) {
[objectsToDelete addObject:object];
}
}
[array removeObjectsInArray:objectsToDelete];
我也有同样的问题。我试过他的第一个答案: 替换
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
借
它现在就像一个符咒。很可能,您在迭代数组时正在更改数组。类似于从循环中的数组中删除对象。