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

时间:2009-08-22 23:02:24

标签: iphone exception subclass core-location

我已经定义了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是一个MyLocation myPosition; self.myPosition = newLocation; [myPosition setDatum:@“WGS 84”]; [myPosition setEllipsoid:@“WGS 84”]; }

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

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

self.myPosition = (MyLocation *)newLocation;

1 个答案:

答案 0 :(得分:0)

newLocation不是ur子类的实例,因此执行该赋值或转换会抛出错误,因为它是无效的转换,你应该从cllocation对象中设置你想要的子类的值

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

等等