didSelectAnnotationView

didSelectAnnotationView

看一下这段代码,看看是否可以帮助我修复它:

- (void)viewDidLoad
{
//Initialize the array and add annotations for the location on the map

annotations = [[NSMutableArray alloc] init];
CustomAnnotation *annotation;
CLLocationCoordinate2D coordinate;

//1
coordinate.latitude = 25.220390105797264;
coordinate.longitude = 55.28095199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"123";

[annotations addObject:annotation];

//2
coordinate.latitude = 25.218880105797264;
coordinate.longitude = 55.27992199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"117";

[annotations addObject:annotation];

//3
coordinate.latitude = 25.219280105797264;
coordinate.longitude = 55.28052199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"118";

[annotations addObject:annotation];

//4
coordinate.latitude = 25.219680105797264;
coordinate.longitude = 55.28052199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"119";

[annotations addObject:annotation];

//5
coordinate.latitude = 25.219980105797264;
coordinate.longitude = 55.28095199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"120";

[annotations addObject:annotation];

//6
coordinate.latitude = 25.220380105797264;
coordinate.longitude = 55.28115199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"121";

[annotations addObject:annotation];

//7
coordinate.latitude = 25.220350105797264;
coordinate.longitude = 55.28105199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"122";

[annotations addObject:annotation];

//8
coordinate.latitude = 25.215050105797264;
coordinate.longitude = 55.28105199798584;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"124";

[annotations addObject:annotation];

//9
coordinate.latitude = -35.44138;
coordinate.longitude = -71.66208;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"125";

[annotations addObject:annotation];

//10
coordinate.latitude = -35.44138;
coordinate.longitude = -71.66208;
annotation = [[CustomAnnotation alloc] initWithCoordinate:coordinate];
annotation.annotationIndex = @"126";

[annotations addObject:annotation];
//Set the region and zoom factor of the map view
MKCoordinateRegion region;

region.span.latitudeDelta = 0.01f;
region.span.longitudeDelta = 0.01f;
region.center.latitude = 25.216050105797264;
    region.center.longitude = 55.27905199798584;
    [sheikhZayedRoadMapView addAnnotations:annotations];
[sheikhZayedRoadMapView setRegion:region];
//[siteMapView.layer setCornerRadius:5.0];
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id <MKAnnotation>)annotation
{
NSLog(@"Annotation Class: %@", [annotation class]);

static NSString * const kPinAnnotationIdentifier = @"PinIdentifier";
MKAnnotationView *annotationView;
Myriadproregular *annotationIndexLabel;
 //CustomAnnotation *customAnnotation =nil
annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:kPinAnnotationIdentifier];
if (!annotationView) {

    annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kPinAnnotationIdentifier];
        annotationIndexLabel = [[Myriadproregular alloc] initWithFrame:CGRectMake(0, 3, 25 , 20)];
        annotationIndexLabel.font = [UIFont boldSystemFontOfSize:12];
        [annotationIndexLabel setBackgroundColor:[UIColor clearColor]];
        [annotationIndexLabel setTextColor:[UIColor whiteColor]];
        [annotationIndexLabel setTextAlignment:UITextAlignmentCenter];
        [annotationView addSubview:annotationIndexLabel];
        annotationView.canShowCallout = YES;
    annotationView.calloutOffset = CGPointMake(-5, 5);

}else {

    //Get the label if exists
    for (UIView *labelView in annotationView.subviews) {
        if ([labelView isKindOfClass:[UILabel class]]) {
            annotationIndexLabel = (Myriadproregular *) labelView;
            break;
        }
    }
}

if ([annotation isKindOfClass:[MKUserLocation class]]) {

    [annotationView setImage:[UIImage imageNamed:@"map_notify_bg.png"]];

}else {
    CustomAnnotation *customAnnotation = (CustomAnnotation *) annotation;
    [annotationIndexLabel setText:customAnnotation.annotationIndex];

    [annotationView setImage:[UIImage imageNamed:@"ico_inspector.png"]];
}

return annotationView;
}


问题是:

当我点击提供给didSelectAnnotationView的自定义图像时,没有得到MKAnnotationView委托方法的调用。

任何帮助将不胜感激。

谢谢

最佳答案

[annotationView setCanShowCallout:NO]

这解决了我的问题,因为我不希望在单击图钉时进行标注,而是希望调用didSelectAnnotationView委托。

谢谢

关于ios - 点击MKAnnotationView不会调用didSelectAnnotationView委托(delegate),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10751052/

10-13 04:28