gpt4 book ai didi

ios - 在 objective-c 中的方法之间传递值

转载 作者:行者123 更新时间:2023-11-29 11:04:01 24 4
gpt4 key购买 nike

<分区>

我很困惑。阅读了大量资源,但没有帮助。如何将一个方法(变量)中生成的值传递给另一个方法,以便它可以用于计算。我找到了一篇关于将属性放入 .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;

拜托,你能帮帮我吗?现在我觉得很愚蠢,因为它必须是一件简单的事情。

问候,

阿德里安

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com