在另一个函数-iOS中使用NSString
我在一个函数中有一些值,它们在那个函数中,我需要在另一个函数中 这些就是价值观在另一个函数-iOS中使用NSString,ios,function,nsstring,Ios,Function,Nsstring,我在一个函数中有一些值,它们在那个函数中,我需要在另一个函数中 这些就是价值观 NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude]; NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude]; NSStri
NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
NSString *stringFromDate = [formatter stringFromDate: newLocation.timestamp];
我需要在另一个函数中使用它们,以便在每次它们找到新位置时将它们发送到我的数据库
有人知道如何修复它吗?我猜您正在使用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
}
谢谢,这听起来太棒了。我明天会试试这个,如果它有效的话,我一定会把它标记为已接受。无论如何,谢谢你!我需要知道的唯一一件事是如何使用textfield执行此操作。但我不会用这个来打扰你。谢谢你帮我做这件事!问候