我很困惑。阅读大量资源,但没有帮助。如何将方法(变量)中生成的值传递给另一种方法,以便将其用于计算。我发现了一篇关于将属性放入 .h 文件的帖子。做过某事。在我的方法中,我首先调用了方法名,然后调用了变量,但它不起作用。这是代码:
-(void)recordLocation{
double valueLat = [[latitude text]doubleValue];
int latSeconds = valueLat * 3600;
int latDegrees = latSeconds / 3600;
latSeconds = abs(latSeconds % 3600);
int latMinutes = latSeconds / 60;
latSeconds %= 60;
char latChar = (latitude > 0) ? 'N' : 'S';
double valueLon = [[longitude text]doubleValue];
int lonSeconds = valueLon * 3600;
int lonDegrees = lonSeconds / 3600;
lonSeconds = abs(lonSeconds % 3600);
int lonMinutes = lonSeconds / 60;
lonSeconds %= 60;
char lonChar = (longitude > 0) ? 'E' : 'W';
CLLocation *tempPos = [[CLLocation alloc] initWithLatitude:valueLat longitude:valueLon]; //tempPos is what I want to pass
NSString *recPosition = [[NSString alloc]initWithFormat:@"%i° %i' %i\" %c" " " @"%i° %i' %i\" %c \n", latDegrees, latMinutes, latSeconds, latChar,lonDegrees, lonMinutes, lonSeconds, lonChar];
_labelDegrees.text = recPosition;
//NSLog(@"%f" , valueLat);
//NSLog(@"%f" , valueLon);
//NSLog (@"%@", tempPos);
}
- (CLLocationDistance)distanceFromLocation{
double lat1 = [[latitude text] doubleValue];
double lon1 = [[longitude text] doubleValue];
CLLocation *currentLocation = [[CLLocation alloc] initWithLatitude:lat1 longitude:lon1];
CLLocationDistance locDistance = [currentLocation distanceFromLocation:recordLocation.tempPos];//tempPos is what I want to use from recordLocation
NSString *distText = [[NSString alloc]initWithFormat:@"%f", locDistance];
//NSLog(@"%f", lat1);
//NSLog(@"%f", lon1);
NSLog(@"%@", currentLocation);
NSLog(@"%@", tempPos);
[lonDistance setText:distText];
}
是变量 tempPos 让我感到痛苦。为了尽可能完整,这是我的 .h 文件。
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import "Corelocation/Corelocation.h"
NSString *latr;
NSString *longr;
NSString *latLabDeg;
NSString *lat;
NSString *lon;
NSString *acc;
double valueLon;
double valueLat;
double latvalue;
double lonvalue;
CLLocation *tempPos;
@interface ViewController : UIViewController <CLLocationManagerDelegate>
@property (strong, nonatomic) IBOutlet UITextField *accuracy;
@property (strong, nonatomic) IBOutlet UITextField *latitude;
@property (strong, nonatomic) IBOutlet UITextField *longitude;
@property (strong, nonatomic) CLLocationManager *location;
@property (strong, nonatomic) IBOutlet UITextField *latrec;
@property (strong, nonatomic) IBOutlet UITextField *longrec;
@property (strong, nonatomic) IBOutlet UILabel *labelDegrees;
@property (strong, nonatomic) IBOutlet UITextField *lonDistance;
@property (nonatomic) CLLocationDistance *locDistance;
@property (retain) CLLocation *tempPos;
//- (CLLocationDistance)distanceFromLocation;
拜托,你能帮帮我吗?现在我觉得很愚蠢,因为它必须是一件简单的事情。
问候,
阿德里