[MKAnnotationView setAnimatesDrop:]:无法识别的选择器已发送到实例但为什么?

问题描述

|
(MKAnnotationView *) mapView:(MKMapView *)theMapView
             viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass: [MyLocation class] ])
    {
        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [theMapView dequeueReusableAnnotationViewWithIdentifier:placemarkIdentifier];
        if(annotationView == nil)
        {
            annotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:placemarkIdentifier];
        }
        else 
        {

            annotationView.annotation = annotation;         
        }

        annotationView.enabled = YES;
        annotationView.animatesDrop = NO;
        annotationView.pinColor = MKPinAnnotationColorPurple;
        annotationView.canShowCallout = YES;
        annotationView.draggable = YES;


       return annotationView;
    }
}
instance1ѭ无法识别的选择器发送到实例。 我使用了许多注释类(MKPinAnnotationView和MKAnnotationView)。因为我使用了dequeueReusableAnnotationViewWithIdentifier,所以可能发生了此错误。     

解决方法

您应该为两种类型的注释视图分配不同的标识符。否则,您将以
MKPinAnnotationView
结尾,而预期只有
MKAnnotationView
,反之亦然(您在这里已经经历过)。