IOS 7 - 添加重叠式崩溃应用 [英] IOS 7 - add overlay crash app

查看:108
本文介绍了IOS 7 - 添加重叠式崩溃应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的应用程序移动到 IOS 7

我有一张地图,并在该地图上绘制 MKPolyLine

一切正常,直到IOS 7现在应用程序崩溃。

我已更改 viewForOverLay with new方法:

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

在ViewDidLoad中我打电话:

In ViewDidLoad I call:

[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)

推荐答案

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

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

这篇关于IOS 7 - 添加重叠式崩溃应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆