gpt4 book ai didi

ios - 抛出 'NSException' 实例后调用终止

转载 作者:行者123 更新时间:2023-11-29 05:04:39 26 4
gpt4 key购买 nike

我尝试运行我的应用程序,但抛出了异常,在控制台中我得到了这个:

2011-05-05 00:18:50.984 myApp[2906:207] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x6b8b780> was mutated while being enumerated.(
"<MyLocation: 0x6b67af0>",
"<MyLocation: 0x6b19360>",
"<MyLocation: 0x6b67a70>",
"<MyLocation: 0x6b8d110>",
"<MyLocation: 0x6b8d280>",
"<MyLocation: 0x6b8ce50>",
"<MyLocation: 0x6b8d660>"
)'
*** Call stack at first throw:
(
0 CoreFoundation 0x02915919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0272a5de objc_exception_throw + 47
2 CoreFoundation 0x029153d9 __NSFastEnumerationMutationHandler + 377
3 myApp 0x00005755 -[StationsSurLaCarteViewController requestFinished:] + 343
4 myApp 0x000195cb -[ASIHTTPRequest reportFinished] + 171
5 Foundation 0x000abe9a __NSThreadPerformPerform + 251
6 CoreFoundation 0x028f6d7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
7 CoreFoundation 0x028552cb __CFRunLoopDoSources0 + 571
8 CoreFoundation 0x028547c6 __CFRunLoopRun + 470
9 CoreFoundation 0x02854280 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x028541a1 CFRunLoopRunInMode + 97
11 GraphicsServices 0x02e8e2c8 GSEventRunModal + 217
12 GraphicsServices 0x02e8e38d GSEventRun + 115
13 UIKit 0x0033ab58 UIApplicationMain + 1160
14 myApp 0x0000224c main + 102
15 myApp 0x000021dd start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
(gdb)

我注意到我得到了这一点,因为我尝试在我的 map View 中使用注释,请帮忙,提前谢谢:)

编辑

这是我的 for 循环,它可能会产生问题:

 for (int i=0; i<[array count]; i++) {

NSDictionary *stationEnCours=[array objectAtIndex:i];


NSString *distance=[stationEnCours objectForKey:@"distance"];
float lng = [[stationEnCours objectForKey:@"ssiphone_longitude"] floatValue];
float lat = [[stationEnCours objectForKey:@"ssiphone_latitude"] floatValue];
NSString *ensStation=[stationEnCours objectForKey:@"ssiphone_enseigne"];

location2D = (CLLocationCoordinate2D){ .latitude = lat, .longitude = lng };
MyLocation *annotation=[[[MyLocation alloc]initWithName:ensStation distanceVersLaStation:distance coordinate:location2D]autorelease];
[mapView addAnnotation:annotation];
MKCoordinateSpan span={latitudeDelta:0.2,longitudeDelta:0.2};
MKCoordinateRegion region={location2D,span};
[mapView setRegion:region];
[self.view addSubview:mapView];
}`

最佳答案

异常的给定原因是“集合...在枚举时发生了变异”。这意味着您尝试在 for( in ) 循环中更改数组,这是不允许的,因为它会更改您应该枚举的对象。原因的结尾是您正在枚举的数组的转储。它包含 7 个 MyLocation 对象。如果查看调用堆栈的顶部,您会发现异常发生在 -[StationsSurLaCarteViewController requestFinished:] 方法中。如果您仔细查看该方法并找到使用快速枚举的地方,您应该很容易找到问题。

如果您想在使用快速枚举时修改数组,有两种可能性:跟踪您想要更改的所有内容(即要删除的索引列表)并在循环后进行更改,或者执行对数组的副本进行枚举。下面是第二种方法的示例:

NSArray *copiedArray = [originalArray copy];
for(id theObject in copiedArray) {
if([theObject shouldBeDeleted]) {
[originalArray removeObject:theObject];
}
}
[copiedArray release];

关于ios - 抛出 'NSException' 实例后调用终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5890998/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com