0

看看这段代码,看看你能不能帮我修复它:

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

任何形式的帮助将不胜感激。

谢谢

4

2 回答 2

3

[annotationView setCanShowCallout:NO]

这解决了我的问题,因为我不想在单击图钉时调用标注,但我想调用要调用的didSelectAnnotationView委托。

谢谢

于 2012-05-28T07:16:26.680 回答
1

你给你的注释一个title属性吗?你确定[annotationView setCanShowCallout:YES]设置正确吗?

于 2012-05-25T10:22:12.027 回答