在 CLLocation 子类上设置属性时出错
的子类
我已经定义了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
newLocation 不是您的子类的实例,因此执行该分配或转换会引发错误,因为它是无效的转换,您应该从 cllocation 对象中设置您想要的子类的值,
等等
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
and so on