Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone IOS 7-添加覆盖崩溃应用程序_Iphone_Ios_Objective C_Mkmapview_Ios7 - Fatal编程技术网

Iphone IOS 7-添加覆盖崩溃应用程序

Iphone IOS 7-添加覆盖崩溃应用程序,iphone,ios,objective-c,mkmapview,ios7,Iphone,Ios,Objective C,Mkmapview,Ios7,我正在将我的应用程序移动到IOS 7 我有一张地图,我在地图上画了MKPolyLine 在IOS 7 now应用程序崩溃之前,一切正常。 我已使用新方法更改了覆盖视图: - (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay { if ([overlay isKindOfClass:[MKPolyline class]]) {

我正在将我的应用程序移动到IOS 7
我有一张地图,我在地图上画了
MKPolyLine

在IOS 7 now应用程序崩溃之前,一切正常。
我已使用新方法更改了覆盖视图:

- (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;
}
这就是实现:

-(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);
});
}
-(无效)绘图路径背景{
对于(int idx=0;idx<[路由计数];idx++)
{
Path*m_p=[routes objectAtIndex:idx];
CLLOCATION坐标2D工作坐标;
工作坐标纬度=m_p.纬度;
工作坐标经度=经度;
MKMapPoint point=MKMAPPOINTFOR坐标(工作坐标);
pointArr[idx]=点;
}
self.routeLine=[MKPolyline polylineWithPoints:pointArr count:[routes count]];
//[self.mapView addOverlay:self.routeLine];
//免费(pointArr);
dispatch\u async(dispatch\u get\u main\u queue()^{
[self.mapView addOverlay:self.routeLine];
免费(pointArr);
});
}

在这一行:
[self.mapView addOverlay:self.routeLine]我得到:EXC\u BAD\u访问(代码=2,地址=0x0)

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

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

使用类似dispatch_async(dispatch_get_main_queue(),^{//your UI operations})的方法;在主线程中分派UI操作。我已更改-(void)drawPathInBackground{…在我的问题(函数结束)中,这样做是否正确?@1110不将生成的MKPolyline存储在属性中。问题是这会引入竞争条件。只需对其使用局部变量(块捕获对象)。使用类似dispatch_async(dispatch_get_main_queue(),^{//your UI operations})的方法在主线程中分派UI操作。我已更改-(void)drawPathInBackground{…在我的问题中(函数结束)这是正确的方法吗?@1110不要将生成的MKPolyline存储在属性中。问题是这会引入竞争条件。只需使用局部变量即可(块捕获对象)。
-(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);
});
}