[英]Unrecognized selector sent to instance while adding annotation in MKMapview
这是在向MKMapView
添加注释时遇到的错误。
我也创建了符合自定义类MKAnnotation
协议有三个@property
: coordinate
, title
和subtitle
。
在这里viewForAnnotation:
方法首先检查注释是哪种类的..检查其YourCustomAnnotationClass
然后里面去,然后检查它不是零,如果nil
然后分配MKAnnotationView
和alloc
,然后编写代码...
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
static NSString *identifier = @"Current";
if ([annotation isKindOfClass:[YourCustomAnnotationClass class]]) { /// check here that is your class annotation or not here..
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) // also check here that it is not nil if nil then alloc it
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
}
/// write your code here
}
return nil;
}
嗨,大家好,我发现自己犯了什么愚蠢的错误,我在自定义注释类中将我的@property命名为CLLocationcoordinate2D,并将其命名为Coordinate,因为它符合KVO投诉,因此不应重命名,因此应按原样使用
@property(nonatomic,assign)CLLocationcoordinate2D坐标;
通过重命名解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.