문제

내 앱에서하는 작업은 다음과 같습니다 :

I 데이터를 핵심 데이터에로드하고 완성 된 앱이 다음 뷰 (Google Map)로 세그리이를 가져 가야합니다 (Google지도)

[self performSegueWithIdentifier:@"loadMap" sender:self];

그러나이 오류가 발생합니다

Terminating app due to uncaught exception 'GMSThreadException', reason: 'All calls to the Google Maps SDK for iOS must be made from the UI thread'

이 모든 것을 수행하지만 버튼을 탭으로 세그리를 만들면 모든 것이 잘 작동합니다.

Storyboard의 Google Map View 컨트롤러에는 init 코드가있는 GMSMAPView View 콘센트가 있습니다

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:45.331875
                                                            longitude:14.450455
                                                                 zoom:14];

    self.mapView.camera = camera;

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = camera.target;
    marker.title = @"Test title";
    marker.snippet = @"Lorem ipsum...";
    marker.map = self.mapView;
.

아무도 여기서 나를 도울 수 있습니까?스토리 보드를 사용하여 프로그래밍 방식으로 Google지도를 사용하여 View 컨트롤러를로드하려면 어떻게합니까?

도움이 되었습니까?

해결책

예외는 백그라운드 스레드에서 세그리를 수행하려고 노력하고있는 것으로 보입니다.충돌에서 멈추려면 주 스레드를 대신 사용해야합니다.다음과 같이 performSegueWithIdentifier:sender:를 다음과 같이 래핑하십시오.

dispatch_async(dispatch_get_main_queue(), ^{
    [self performSegueWithIdentifier:@"loadMap" sender:self];
});
.

다른 팁

스위프트 용 :

dispatch_async(dispatch_get_main_queue(), {})
.

해당 curlies에서 코드를 던지십시오 ...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top