2011-02-09 63 views
0

我在嘗試訪問CLLocation時遇到錯誤,請問您能解釋原因嗎?CLLocation EXC_BAD_ACCESS

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

我geeting反饋用於從所述位置管理器的位置:

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

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

的LocationManager:< 36.45307493, 28.22220462> +/-100.00米(速度-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); 

} 

能否請您解釋一下爲什麼我不能訪問它?

非常感謝!

回答

3

您不保留位置。這樣做:

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

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