2013-04-20 4 views
0

추가 할 때지도가 응답하지 않게되는 것을 막기 위해 배경에 마커를 추가하려고하지만 이전에 결코 만난 적이없는 오류가 나타납니다.배경에 마커 추가

여기에 백그라운드에서 마커를로드하려는 시도가 있으며 addMarkerWithOptions를 보내려고 할 때 오류가 발생합니다. this documentation에 따르면 오류

yeap im in the background 860, markers=0 
2013-04-20 14:02:11.561 Skate-Spots[7796:907] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSSetM: 0x1d6e7880> was mutated while being enumerated.' 
*** First throw call stack: 
(0x336a23e7 0x3b39d963 0x336a1ec1 0x16ea0d 0x3b7b7793 0x3b7b75db 0x3b7bae45 0x336761b1 0x335e923d 0x335e90c9 0x371c833b 0x355052b9 0x112e5 0x3b7cab20) 
libc++abi.dylib: terminate called throwing an exception 

답변

1

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    NSLog(@"yeap im in the background %i, markers=%i", [[self visibleLocations] count], [[[self googleMap] markers] count]); 
    for (int i = 0; i < self.visibleLocations.count; i++) { 
     Location *location = [self.visibleLocations objectAtIndex:i]; 
     GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init]; 
     options.position = CLLocationCoordinate2DMake([location.lat floatValue], [location.lng floatValue]); 
     options.title = [NSString stringWithFormat:@"(%i) %@", location.mapNeighbors.count, location.title]; 
     options.icon = [UIImage imageNamed:@"search_measle_small.png"]; 
     [self.googleMap addMarkerWithOptions:option]; 
    } 
}); 

:

GMSMapView는 읽기 전용 및 모든 UIKit 객체에 유사한 메인 쓰레드에서 수정할 수 있습니다. 다른 스레드에서 이러한 메서드를 호출하면 예외 또는 정의되지 않은 동작이 발생합니다.

0
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    NSLog(@"yeap im in the background %i, markers=%i", [[self visibleLocations] count], [[[self googleMap] markers] count]); 
    for (int i = 0; i < self.visibleLocations.count; i++) { 
     Location *location = [self.visibleLocations objectAtIndex:i]; 
     GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init]; 
     options.position = CLLocationCoordinate2DMake([location.lat floatValue], [location.lng floatValue]); 
     options.title = [NSString stringWithFormat:@"(%i) %@", location.mapNeighbors.count, location.title]; 
     options.icon = [UIImage imageNamed:@"search_measle_small.png"]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 
     [self.googleMap addMarkerWithOptions:option]; 
     }); 
    } 
}); 
+1

오류를 설명하고 설명해야합니다. – blue