将MKPolyline Overlay添加到MKMapView会导致应用程序崩溃 [英] Adding MKPolyline Overlay to MKMapView crashes application

查看:104
本文介绍了将MKPolyline Overlay添加到MKMapView会导致应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在iOS6上运行正常,但是当我向MKMapView添加叠加时,由于访问不良而导致iOS 7崩溃。我的代码如下:

My application was working fine on iOS6 but it is crashing on iOS 7 due to bad access when I add overlay to MKMapView.My code is as follows

MKPolyline *polyline = [[MKPolyline alloc] init];
   polyline = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
    [directionMap addOverlay:polyline];

这是崩溃日志
(lldb)bt
*

This is the crash log (lldb) bt *

 thread #51: tid = 0x1cc5, 0x38755f8c libdispatch.dylib`dispatch_retain$VARIANT$mp + 8, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x38755f8c libdispatch.dylib`dispatch_retain$VARIANT$mp + 8
    frame #1: 0x3598dbc8 VectorKit`-[VKRasterOverlayTileSource init] + 176
    frame #2: 0x358cfd24 VectorKit`-[VKMapModel _rasterOverlayTileSourceForLevel:] + 308
    frame #3: 0x358d0226 VectorKit`-[VKMapModel addRasterOverlay:] + 46
    frame #4: 0x2f068dfe MapKit`-[MKOverlayContainerView _insertDrawable:forOverlay:atIndex:level:] + 1010
    frame #5: 0x2f06752e MapKit`-[MKOverlayContainerView _configureAndAddDrawable:forOverlay:level:] + 326
    frame #6: 0x2f0676ac MapKit`-[MKOverlayContainerView _considerAddingDrawable:inAddRect:level:] + 372
    frame #7: 0x2f067cce MapKit`-[MKOverlayContainerView addOverlay:level:] + 246
    frame #8: 0x001394c8 Falcon`-[GetDirectionVC showRouteFrom:to:](self=0x19742820, _cmd=0x001fa466, f=CLLocationCoordinate2D at 0x04f9ec2c, t=CLLocationCoordinate2D at 0x04f9ec1c) + 956 at GetDirectionVC.m:226
    frame #9: 0x001390ee Falcon`-[GetDirectionVC loadLocations](self=0x19742820, _cmd=0x001fa458) + 1314 at GetDirectionVC.m:173
    frame #10: 0x2e876e26 Foundation`__NSThread__main__ + 1062
    frame #11: 0x38891c1c libsystem_pthread.dylib`_pthread_body + 140
    frame #12: 0x38891b8e libsystem_pthread.dylib`_pthread_start + 102

(lldb)

推荐答案

我遇到了同样的问题,堆栈跟踪看起来很容易让我误解。我的错误修正是明确地在主线程上添加叠加:

I had the same problem, the stack trace looks misleading to me. My bugfix is to explicitely add the overlay on the main thread:

dispatch_async(dispatch_get_main_queue(), ^{
  [mapView addOverlay:myRouteLine];
});

或者如果你想使用新的MKOverlayRenderer:

or if you'd like to use the new MKOverlayRenderer:

dispatch_async(dispatch_get_main_queue(), ^{
  [mapView addOverlay:myRouteLine level:MKOverlayLevelAboveRoads];
});

在我的情况下,我正在异步下载一些数据,生成折线,创建MKOverlayViews / MKOverlayRenderes(didn)帮助替换已弃用的代码,并将叠加层添加到地图中。

In my case, I'm downloading asynchronously some data, generate Polylines, create MKOverlayViews / MKOverlayRenderes (didn't help to replace the deprecated code) and add the overlay to the map.

这篇关于将MKPolyline Overlay添加到MKMapView会导致应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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