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:
我正在将我的应用程序移动到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;
}
In ViewDidLoad I call:
在ViewDidLoad中,我调用:
[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)
在这一行:[self.mapView addOverlay:self.routeLine];我得到:EXC_BAD_ACCESS(代码= 2,地址= 0x0)
1 个解决方案
#1
7
You are not supposed to do ANY UI operations on a background thread. UI on the main thread ONLY.
您不应该在后台线程上执行任何UI操作。仅在主线程上的UI。
#1
7
You are not supposed to do ANY UI operations on a background thread. UI on the main thread ONLY.
您不应该在后台线程上执行任何UI操作。仅在主线程上的UI。