gpt4 book ai didi

ios - 发送到实例的无法识别的选择器?

转载 作者:行者123 更新时间:2023-11-28 22:33:15 25 4
gpt4 key购买 nike

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

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

谢谢。

最佳答案

您可能在 initWithCoordinate:... 方法中执行类似的操作:

self.coordinate = c;

这不是一个简单的赋值,这是调用一个不存在的方法(属性 setter setCoordinate:),它以异常结束。

修复编译器警告!

关于ios - 发送到实例的无法识别的选择器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16843675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com