CLLocation获得EXC_BAD_ACCESS

时间:2011-02-09 08:30:22

标签: iphone mkmapview

我在尝试访问CLLocation时遇到错误,您能解释一下原因吗?

CLLocation *currentLocation;
@property (nonatomic, retain) CLLocation *currentLocation;

我正在通过位置管理员对该位置进行反馈:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    if (newLocation != nil) {
        currentLocation = newLocation;
        NSLog(@"locationManager: %@", currentLocation);
    }
}
  

locationManager:< +36.45307493,   + 28.22220462> +/- 100.00m(速度-1.00 mps /航向-1.00)@ 9/2/11 10:14:58   π.μ. GMT + 02:00

但是当我尝试从DidSelectAnnotationView访问currentLocation时,我得到了EXC_BAD_ACCESS:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {

    NSLog(@"current Location: %@", currentLocation);

}

你可以解释为什么我无法访问它吗?

非常感谢!

1 个答案:

答案 0 :(得分:3)

您没有保留该位置。这样做:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    if (newLocation != nil) {
        self.currentLocation = newLocation; /// The change is here
        NSLog(@"locationManager: %@", currentLocation);
    }
}