IOS 7 - add overlay crash app

家住魔仙堡 提交于 2019-12-24 09:49:58

问题


I am in a process of moving my app to IOS 7.
I have a map and on that map I draw MKPolyLine.
Everything worked until IOS 7 now app crash.
I have changed viewForOverLay with new method:

- (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;
}

In ViewDidLoad I call:

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

And this is the implementation:

-(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);
});
}

On this line: [self.mapView addOverlay:self.routeLine]; I get: EXC_BAD_ACCESS(code = 2, address = 0x0)


回答1:


You are not supposed to do ANY UI operations on a background thread. UI on the main thread ONLY.



来源:https://stackoverflow.com/questions/19025148/ios-7-add-overlay-crash-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!