[MKMapView setShowsUserLocation] 中的 EXC_BAD_ACCESS
我在一段相对简单的代码中得到了令人讨厌的 EXC_BAD_ACCESS 。有谁知道这段代码为何崩溃?
stack:
_remove ()
-[MKQuadTrie remove:] ()
-[MKAnnotationContainerView removeAnnotation:] ()
-[MKMapView(UserPositioningInternal) removeUserLocation] ()
-[MKMapView(UserPositioning) stopUpdatingUserLocation] ()
-[MKMapView setShowsUserLocation:] ()
-[MapViewController stopTrackingLocation]
code:
- (void)stopTrackingLocation
{
if (mapView.showsUserLocation)
{
// Crashes here
mapView.showsUserLocation = NO;
}
}
I'm getting the nasty EXC_BAD_ACCESS in a relatively straightforward piece of code. Does any one have any idea why this code crashes?
stack:
_remove ()
-[MKQuadTrie remove:] ()
-[MKAnnotationContainerView removeAnnotation:] ()
-[MKMapView(UserPositioningInternal) removeUserLocation] ()
-[MKMapView(UserPositioning) stopUpdatingUserLocation] ()
-[MKMapView setShowsUserLocation:] ()
-[MapViewController stopTrackingLocation]
code:
- (void)stopTrackingLocation
{
if (mapView.showsUserLocation)
{
// Crashes here
mapView.showsUserLocation = NO;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是新手,但我只是想提供帮助。
您的应用程序是否在您刚刚启动应用程序时失败?
我认为它显示访问错误,因为获取您的位置需要时间,并且您在 GPS 获取位置数据之前访问它。
因此,为了防止这种情况,我将使用 didupdatetolocation: 方法。
将位置数据分配给“something”,
因此如果“something”不为零,则仅mapview.showsuserlocation = NO;
I'm a newbie but I'm just trying to help.
Is your application failing at the point where you just start your app?
I think it shows bad access because getting your location takes time, and you access it before your gps get the location data.
So to prevent this I will use the didupdatetolocation: method.
Assign the location data into "something"
so if "something" is not nil, then only mapview.showsuserlocation = NO;
当您尝试访问不存在的对象时,您会收到此错误。您确定在调用
- stopTrackingLocation
之前没有从内存中释放mapView
吗?This error you use to get when you try access non existing object. Are you sure
mapView
was not released from memory before- stopTrackingLocation
call?