2012-09-04 5 views
-1

다른 함수에서 필요한 함수에 몇 가지 값이 있습니다.다른 함수에서 NSString 사용하기 - iOS

다음은 값입니다.

NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude]; 
NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude]; 
NSString *stringFromDate = [formatter stringFromDate: newLocation.timestamp]; 

다른 위치에서 새 위치를 찾을 때마다 내 데이터베이스로 보내려면이 기능이 필요합니다.

누구든지 문제를 해결할 방법을 알고 있습니까?

답변

3

CLLocationManagerDelegate를 사용하고 있다고 가정합니까? 새 위치가이 방법에의 전송을 발견 그래서

:이 데이터베이스에 값을 기록하여 메서드를 호출하고 매개 변수로 당신있는 거 값을 전달할 수 있습니다에서

– (void)locationManager:didUpdateToLocation:fromLocation: 

. 예 :

– (void)locationManager:(CLLocationManager *)locationManager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)newLocation { 
    NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude]; 
    NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude]; 
    NSString *stringFromDate = [formatter stringFromDate: newLocation.timestamp]; 

    [self myFuntionThatWritesToDatabaseWithLatitude:latitude longitude:longitude date:stringFromDate]; 
} 

- (void)myFuntionThatWritesToDatabaseWithLatitude:(NSString *)latitude longitude:(NSString *)longitude date:(NSString *)stringFromDate { 
    // write to Database 
} 
+0

감사합니다. 매우 멋진 소리입니다. 나는 이것을 내일 시도 할 것이고, 그것이 효과가 있다면 나는 이것을 인정 된 것으로 확실히 표시 할 것이다. 고맙습니다 어쨌든 –

+0

정말 고마워요! 내가 알아야 할 유일한 것은 텍스트 필드로 이것을하는 방법입니다. 그러나 나는 그걸로 당신을 괴롭히지 않을 것입니다. 이걸 도와 주셔서 감사합니다! 환영합니다. –

+0

여러분, 환영합니다. –

관련 문제