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

Are you giving your annotations a title property? Are you sure that [annotationView setCanShowCallout:YES] is set properly?

于 2012-05-25T10:22:12.027 に答える