0

如何修复这样的错误:无法识别的选择器发送到实例?

CLLocationCoordinate2D userCoordinate = userLocation.location.coordinate;
CGFloat latDelta = rand()*.035/RAND_MAX -.02;
CGFloat longDelta = rand()*.03/RAND_MAX -.015;
CLLocationCoordinate2D newCoord = { userCoordinate.latitude + latDelta, userCoordinate.longitude + longDelta };
myPoint *mp = [[myPoint alloc] initWithCoordinate:newCoord title:[NSString stringWithFormat:@"Vitaliy Home %d",i] subTitle:@"Home Sweet Home"];
[mv addAnnotation:mp]; //mv - (MKMapView *)mv

错误在线:

myPoint *mp = [[myPoint alloc] initWithCoordinate:newCoord title:[NSString stringWithFormat:@"Vitaliy Home %d",i] subTitle:@"Home Sweet Home"];

类我点:

@interface myPoint : NSObject<MKAnnotation> {
    NSString *title;
    NSString *subTitle;
    CLLocationCoordinate2D coordinate;
}

@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic,copy) NSString *title;
@property (nonatomic,copy) NSString *subTitle;

- (id)initWithCoordinate:(CLLocationCoordinate2D) c title:(NSString *) t subTitle:(NSString *) st;

@end

谢谢你。

4

2 回答 2

2

您可能在initWithCoordinate:...方法中执行以下操作:

self.coordinate = c;

这不是一个简单的分配,这是调用一个setCoordinate:不存在的方法(属性设置器),它以异常结束。

修复编译器警告!

于 2013-05-30T18:59:13.907 回答
0

问题在于该方法的实施不正确,感谢@BrunoKoga。

于 2013-05-30T18:59:53.690 回答