I want to send longitude
and latitude
values from the FirstViewController
to another view controller but when passing the variables, their values are set to null and I had an error message : message sent to deallocated instance
, here is my code:
FirstViewController
NSString *nomDClient, *lat, *longt;
int degrees;
double decimal;
int minutes;
double seconds;
- (void)viewDidLoad {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
degrees = newLocation.coordinate.latitude;
decimal = fabs(newLocation.coordinate.latitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",degrees, minutes, seconds];
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"", degrees, minutes, seconds];
NSLog (@"%@Longitude", longt); // here I can get longitude value correctly
}
- (IBAction)pushSecondView:(id)sender {
MC_AutourDeMoi *controller = [[MC_AutourDeMoi alloc] initWithNibName:@"MC_AutourDeMoi" bundle:nil];
controller.longitudeUser = longt;
[self.navigationController pushViewController:controller animated:YES];
}
- (void)dealloc {
[btn1 release];
[locationManager release];
[super dealloc];
}