1

我正在将我的应用程序移至IOS 7
我有一张地图,我在这张地图上画MKPolyLine
一切正常,直到 IOS 7 现在应用程序崩溃。
viewForOverLay用新方法改变了:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
    if ([overlay isKindOfClass:[MKPolyline class]]) {
        MKPolyline *route = overlay;
        MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc] initWithPolyline:route];
        routeRenderer.strokeColor = [UIColor redColor];
        routeRenderer.lineWidth = 7;
        return routeRenderer;
    }
    else return nil;
}

在 ViewDidLoad 我调用:

[self performSelectorInBackground:@selector(drawPathInBackground) withObject:nil];

这是实现:

-(void)drawPathInBackground{
for(int idx = 0; idx < [routes count]; idx++)
    {
        Path *m_p = [routes objectAtIndex:idx];
        CLLocationCoordinate2D workingCoordinate;
        workingCoordinate.latitude=m_p.Latitude;
        workingCoordinate.longitude=m_p.Longitude;
        MKMapPoint point = MKMapPointForCoordinate(workingCoordinate);
        pointArr[idx] = point;
    }
    self.routeLine = [MKPolyline polylineWithPoints:pointArr count:[routes count]];
    //[self.mapView addOverlay:self.routeLine];
    //free(pointArr);
    dispatch_async(dispatch_get_main_queue(), ^{
    [self.mapView addOverlay:self.routeLine];
    free(pointArr);
});
}

在这一行:[self.mapView addOverlay:self.routeLine];我得到:EXC_BAD_ACCESS(code = 2, address = 0x0)

4

1 回答 1

7

您不应该在后台线程上执行任何 UI 操作。仅在主线程上的 UI。

于 2013-09-26T10:05:19.257 回答