0
獲得價值
我構建了一系列MKPolygons的並將它們存儲在NSValues數組:EXC_BAD_ACCESS從NSValue
for (NSDictionary* country in countries) {
NSMutableArray* polygons = [[NSMutableArray alloc] init];
for (NSArray* polygon in [country objectForKey:@"polygons"]) {
CLLocationCoordinate2D polygonCoords[polygon.count];
int i;
for (i = 0; i < polygon.count; i++) {
NSValue* coords = [polygon objectAtIndex:i];
CLLocationCoordinate2D stored_coords;
[coords getValue:&stored_coords];
polygonCoords[i] = stored_coords;
}
MKPolygon* poly = [MKPolygon polygonWithCoordinates:polygonCoords count:polygon.count];
[polygons addObject:[NSValue valueWithBytes:&poly objCType:@encode(MKPolygon)]];
[chillPillMap addOverlay:poly];
}
[country setValue:polygons forKey:@"polygon_objects"];
}
然而,當我稍後再嘗試訪問它們,我得到的是兩個或三個,併發生EXC_BAD_ACCESS:
for (NSDictionary* country in countries) {
NSArray* polygon_objects = [country objectForKey:@"polygon_objects"];
int i;
for (i = 0; i < polygon_objects.count; i++) {
MKPolygon* saved_poly = [MKPolygon alloc];
[[polygon_objects objectAtIndex:i] getValue:&saved_poly];
}
}
不確定這是爲什麼。
你可以張貼的錯誤,他們出現什麼線路上? – 2012-04-24 23:52:58