IOS 7 - 添加重叠式崩溃应用

时间:2013-09-26 10:00:31

标签: iphone ios objective-c mkmapview ios7

我正在将我的应用移至 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(代码= 2,地址= 0x0)

1 个答案:

答案 0 :(得分:7)

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