방금 Objective C로 코딩을 시작했고, 사용자 위치를 추적 할 앱을 만들고, 그 안에 latlng으로 경고를 보냅니다. 이 코드는 조금이라도 완벽하지는 않지만 경고를 위해 "viewDidLoad"에서 "lat"를 만든 변수를 사용하는 데 문제가 발생했습니다. CLLocationManager 대리자/메서드에서 변수를 선언했는데 다른 곳에서 사용하는 방법을 모르겠습니다.다른 메소드에서 선언 된 변수를 다른 메소드로 사용하기
- (void)viewDidLoad
{
locationManager =[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 100.0f;
[locationManager startUpdatingLocation];
UIAlertView *message = [[UIAlertView alloc] initWithTitle: @"Your current Latitude is:"
message:This is where I want to put the variable "lat"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
은}
-(void) locationmanager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation
{
NSString *lat = [[NSString alloc] initWithFormat: @"%g",newLocation.coordinate.latitude];
NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
}
어떤 도움을 주시면 감사하겠습니다!
이 모든 클래스가 있습니까? –
예, 그렇게 생각합니다. – michael03m
.h 파일에서 선언 한 변수를 @synthesize하는 것을 잊어 버렸습니다. – michael03m