[MKMapView setShowsUserLocation] 中的 EXC_BAD_ACCESS

发布于 2024-11-30 23:29:07 字数 527 浏览 2 评论 0原文

我在一段相对简单的代码中得到了令人讨厌的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满身野味 2024-12-07 23:29:07

我是新手,但我只是想提供帮助。
您的应用程序是否在您刚刚启动应用程序时失败?
我认为它显示访问错误,因为获取您的位置需要时间,并且您在 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;

擦肩而过的背影 2024-12-07 23:29:07

当您尝试访问不存在的对象时,您会收到此错误。您确定在调用 - 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文