在 CLLocation 子类上设置属性时出错

发布于 2024-08-02 10:04:20 字数 880 浏览 1 评论 0原文

的子类

我已经定义了 CLLocation MyLocation.h

@interface MyLocation: CLLocation {
    NSString *datum;
    NSString *ellipsoid;
}

@property(nonatomic,retain) NSString *ellipsoid;
@property(nonatomic,retain) NSString *datum;

MyLocation.m

@synthesize datum,ellipsoid;

现在我通过位置管理器委托获得了一个 CLLocation 实例

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    //self.myPosition is a MyLocation myPosition;
    self.myPosition = newLocation;
    [myPosition setDatum: @"WGS 84"];
    [myPosition setEllipsoid: @"WGS 84"];
}

当我执行 self.myPosition = newLocation 时,我得到了一个 UNCAUGHT EXCEPTION 并且它死掉了

我也尝试过这种方式,结果相同:

self.myPosition = (MyLocation *)newLocation;

I've defined this subclass of CLLocation

MyLocation.h

@interface MyLocation: CLLocation {
    NSString *datum;
    NSString *ellipsoid;
}

@property(nonatomic,retain) NSString *ellipsoid;
@property(nonatomic,retain) NSString *datum;

MyLocation.m

@synthesize datum,ellipsoid;

Now I get a CLLocation instance through the location manager delegate

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    //self.myPosition is a MyLocation myPosition;
    self.myPosition = newLocation;
    [myPosition setDatum: @"WGS 84"];
    [myPosition setEllipsoid: @"WGS 84"];
}

When I do the self.myPosition = newLocation, I get an UNCAUGHT EXCEPTION and it dies

I've also tried this way with same results:

self.myPosition = (MyLocation *)newLocation;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吻风 2024-08-09 10:04:21

newLocation 不是您的子类的实例,因此执行该分配或转换会引发错误,因为它是无效的转换,您应该从 cllocation 对象中设置您想要的子类的值,

self.myPosition=[[MyLocation alloc] initWithCoordinate:newLocation.coordinate]

等等

newLocation is not an instance of ur subclass so doing that assignment or casting throws an error because it's an invalid cast, u should be seting the values of ur subclass that u want fromthe cllocation object something like

self.myPosition=[[MyLocation alloc] initWithCoordinate:newLocation.coordinate]

and so on

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文