2009-08-22 129 views
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是MyLocation myPosition; self.myPosition = newLocation; [myPosition setDatum:@「WGS 84」]; [myPosition setEllipsoid:@「WGS 84」]; }

當我做self.myPosition = newLocation我得到一個未捕獲的異常,以至於死

我也試過這種方式具有相同的結果:

self.myPosition = (MyLocation *)newLocation; 

回答

0

newLocation不你的子類的一個實例,這樣做,賦值或鑄造拋出一個錯誤,因爲它是一個無效的強制轉換,你應該設置你想從cllocation對象中得到的子類的值,如

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