开发者

EXC_BAD_ACCESS in [MKMapView setShowsUserLocation]

开发者 https://www.devze.com 2023-03-30 10:34 出处:网络
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?

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:] ()
-[MKAnnot开发者_C百科ationContainerView removeAnnotation:] ()
-[MKMapView(UserPositioningInternal) removeUserLocation] ()
-[MKMapView(UserPositioning) stopUpdatingUserLocation] ()
-[MKMapView setShowsUserLocation:] ()
-[MapViewController stopTrackingLocation]

code:
- (void)stopTrackingLocation 
{
    if (mapView.showsUserLocation)
    {
        // Crashes here
        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;


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消