Adding MKPolyline Overlay to MKMapView crashes application

前端 未结 2 1431
臣服心动
臣服心动 2020-12-31 23:43

My application was working fine on iOS6 but it is crashing on iOS 7 due to bad access when I add overlay to MKMapView.My code is as follows

MKPolyline *polyl         


        
相关标签:
2条回答
  • 2021-01-01 00:16

    Use following If you are creating poly lines in thread other than main thread:

    [self performSelectorOnMainThread:@selector(addPolyLineToMap:) withObject:polyline waitUntilDone:NO];
    
    -(void)addPolyLineToMap:(MKPolyline*)apolyline{
        [mapview addOverlay:apolyline];
    }
    
    0 讨论(0)
  • 2021-01-01 00:17

    I had the same problem, the stack trace looks misleading to me. My bugfix is to explicitely add the overlay on the main thread:

    dispatch_async(dispatch_get_main_queue(), ^{
      [mapView addOverlay:myRouteLine];
    });
    

    or if you'd like to use the new MKOverlayRenderer:

    dispatch_async(dispatch_get_main_queue(), ^{
      [mapView addOverlay:myRouteLine level:MKOverlayLevelAboveRoads];
    });
    

    In my case, I'm downloading asynchronously some data, generate Polylines, create MKOverlayViews / MKOverlayRenderes (didn't help to replace the deprecated code) and add the overlay to the map.

    0 讨论(0)
提交回复
热议问题