繁体   English   中英

在MKMapview中添加注释时,无法识别的选择器发送到实例

[英]Unrecognized selector sent to instance while adding annotation in MKMapview

这是在向MKMapView添加注释时遇到的错误。

我也创建了符合自定义类MKAnnotation协议有三个@propertycoordinatetitlesubtitle

在此处输入图片说明

在这里viewForAnnotation:方法首先检查注释是哪种类的..检查其YourCustomAnnotationClass然后里面去,然后检查它不是零,如果nil然后分配MKAnnotationViewalloc ,然后编写代码...

- (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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM