gpt4 book ai didi

ios - CLLocation 速度不显示在 UIView 上

转载 作者:行者123 更新时间:2023-11-29 10:55:39 28 4
gpt4 key购买 nike

我对 iOS 编码还很陌生。我需要一些帮助来解决 CLLocation 的问题。

我使用 didUpdateLocations 来检索位置和速度信息。我能够使用 NSLog 获取这些详细信息并显示。

但是,我无法在 UIview 上显示它。我该如何解决?

下面是我的代码。

我使用 CoreLocationController 来检索我的位置详细信息。

@implementation CoreLocationController

@synthesize locMgr;
@synthesize location;

- (id)init {
self = [super init];

if(self != nil) {
self.locMgr = [[CLLocationManager alloc] init];
self.locMgr.delegate = self;
}

return self;
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
DriveTrapViewController *driveTrapViewController = [[DriveTrapViewController alloc]init];

self.location = [locations lastObject];
//NSLog(@"Speed, %f", self.location.speed);
[driveTrapViewController locationUpdate:(CLLocation *)self.location];
}

我将检索到的详细信息发送回 DriveTrapViewController。我可以使用 NSLog 显示它们。但是 self.speedText.text 始终为 NULL,屏幕上没有显示任何内容。

@implementation DriveTrapViewController

@synthesize CLController;
@synthesize speedText = _speedText;
- (void)viewDidLoad {
[super viewDidLoad];
CLController = [[CoreLocationController alloc] init];

CLController.delegate = self;
[CLController.locMgr startUpdatingLocation];
}

- (void)locationUpdate:(CLLocation *)location
{
NSString *speed = [NSString stringWithFormat:@"SPEED: %f", location.speed];
NSLog(@"Speed %@",speed);
self.speedText.text = speed;
}

我该如何解决这个问题?任何帮助表示赞赏。谢谢

最佳答案

每次您的 locationManager:didUpdateLocations: 方法被调用时,它都会创建一个新的 DriveTrapViewController,该方法一完成就会被销毁。也许您应该为此使用 ivar。这样它就不会每次都被创建和销毁。

此外,这两个对象似乎都在创建另一个对象的实例。这不是核心位置问题,而是一般架构类型的问题。

我建议在这个阶段你应该在你的 DriveTrapController 中有一个 CLLocationManager 变量,而不是试图将它分解成它自己的 Controller 。

关于ios - CLLocation 速度不显示在 UIView 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18541534/

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